Hallo
Das Programm an sich funktioniert soweit.
-> Es liest Zellen aus einer Excel-Tabelle aus und soll diese in ein txt-Doc speichern.
Vielleicht weiß einer eine Möglichkeit den Text zu vereinfachen.
Und wie ich anschließend die Werte in eine txt.-datei schreiben kann.
Und wie ich überprüfen kann, ob die nächste Spalte/Zeile leer ist.
Ich hoffe mir kann jemand helfen!
Dank schon mal
Alles anzeigen
Das Programm an sich funktioniert soweit.
-> Es liest Zellen aus einer Excel-Tabelle aus und soll diese in ein txt-Doc speichern.
Vielleicht weiß einer eine Möglichkeit den Text zu vereinfachen.
Und wie ich anschließend die Werte in eine txt.-datei schreiben kann.
Und wie ich überprüfen kann, ob die nächste Spalte/Zeile leer ist.
Ich hoffe mir kann jemand helfen!
Dank schon mal
Quellcode
- Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
- excel.Visible = false;
- object missing = Missing.Value;
- string fileName = Path.Combine(System.Windows.Forms.Application.StartupPath, tDateipfad.Name);
- Microsoft.Office.Interop.Excel.Workbook workbook = excel.Workbooks.Open(fileName, missing, missing, missing,
- missing, missing, missing, missing, missing, missing, missing, missing, missing,
- missing, missing);
- object sheet = excel.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, excel, new object[0]);
- StreamWriter myFile = new StreamWriter(tspeicherpfad.Name);
- string domain = "Domain";
- string wert = "Wert";
- string deutsch = "deutsch";
- string englisch = "englisch";
- //Domain
- object DomainA1 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "A1", Missing.Value });
- string dA1 = Convert.ToString(DomainA1.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, DomainA1, new object[0]));
- if (dA1 != domain)
- {
- object DomainB1 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "B1", Missing.Value });
- string dB1 = Convert.ToString(DomainB1.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, DomainB1, new object[0]));
- if (dB1 != domain)
- {
- object DomainC1 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "C1", Missing.Value });
- string dC1 = Convert.ToString(DomainC1.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, DomainC1, new object[0]));
- if (dC1 != domain)
- {
- object DomainD1 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "D1", Missing.Value });
- string dD1 = Convert.ToString(DomainD1.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, DomainD1, new object[0]));
- if (dD1 != domain)
- {
- object DomainE1 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "E1", Missing.Value });
- string dE1 = Convert.ToString(DomainE1.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, DomainE1, new object[0]));
- if (dE1 != domain)
- {
- object DomainF1 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "F1", Missing.Value });
- string dF1 = Convert.ToString(DomainF1.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, DomainF1, new object[0]));
- if (dF1 != domain)
- {
- object DomainG1 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "G1", Missing.Value });
- string dG1 = Convert.ToString(DomainG1.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, DomainG1, new object[0]));
- if (dG1 != domain)
- {
- object DomainH1 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "H1", Missing.Value });
- string dH1 = Convert.ToString(DomainH1.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, DomainH1, new object[0]));
- if (dH1 != domain)
- {
- MessageBox.Show("Domain nicht enthalten");
- }
- else
- {
- object domainH2 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "H2", Missing.Value });
- string doH2 = Convert.ToString(domainH2.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, domainH2, new object[0]));
- if (doH2 == "") { goto NEXT; }
- ...bis H12
- }
- }
- else
- {
- object domainG2 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "G2", Missing.Value });
- string doG2 = Convert.ToString(domainG2.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, domainG2, new object[0]));
- if (doG2 == "") { goto NEXT; }
- ...bis G12
- }
- }
- else
- {
- object domainF2 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "F2", Missing.Value });
- string doF2 = Convert.ToString(domainF2.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, domainF2, new object[0]));
- if (doF2 == "") { goto NEXT; }
- ...bis F12
- }
- }
- else
- {
- object domainE2 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "E2", Missing.Value });
- string doE2 = Convert.ToString(domainE2.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, domainE2, new object[0]));
- if (doE2 == "") { goto NEXT; }
- ...bis E12
- }
- }
- else
- {
- object domainD2 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "D2", Missing.Value });
- string doD2 = Convert.ToString(domainD2.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, domainD2, new object[0]));
- if (doD2 == "") { goto NEXT; }
- ...bis D12
- }
- }
- else
- {
- object domainC2 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "C2", Missing.Value });
- string doC2 = Convert.ToString(domainC2.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, domainC2, new object[0]));
- if (doC2 == "") { goto NEXT; }
- ...bis C12
- }
- }
- else
- {
- object domainB2 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "B2", Missing.Value });
- string doB2 = Convert.ToString(domainB2.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, domainB2, new object[0]));
- if (doB2 == "") { goto NEXT; }
- ...bis B12
- }
- }
- else
- {
- object domainA2 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "A2", Missing.Value });
- string doA2 = Convert.ToString(domainA2.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, domainA2, new object[0]));
- if (doA2 == "") { goto NEXT; }
- ...bis A12
- object domainA12 = sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, sheet, new object[2] { "A12", Missing.Value });
- string doA12 = Convert.ToString(domainA12.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, domainA12, new object[0]));
- if (doA12 == "") { goto NEXT; }
- }
- NEXT:
- //Wert
- NEXT1:
- //deutsch
- NEXT2:
- //englisch
- //3 weitere Abfragen (das selbe)
- End:
- //Werte in txt-Datei schreiben
- myFile.Close();
- excel.Quit();