Hello,
We have the following problem:
by Creating and filling an Excel file with TMS Flexcel Studio it will be damage
and can not be repaired.
A snippet of the right file "workbook.xml" from the Excel file before editing with Flexcel:
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<fileVersion appName="xl" lastEdited="5" lowestEdited="4" rupBuild="9303"/>
<workbookPr defaultThemeVersion="124226"/><bookViews><workbookView xWindow="0" yWindow="0" windowWidth="19200" windowHeight="10785"/></bookViews>
<sheets><sheet name="RM 997" sheetId="3" r:id="rId1"/></sheets><calcPr calcId="0"/></workbook>
A snippet of the corrupt file "workbook.xml" from the Excel file after editing with Flexcel:
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<fileVersion appName="xl" rupBuild="4506" lastEdited="4" lowestEdited="4" />
<workbookPr defaultThemeVersion="124226" /><bookViews><workbookView xWindow="0" yWindow="0" windowWidth="19200" windowHeight="10785" /></bookViews>
<sheets><sheet name="RM 997" sheetId="3" r:id="flId1" /></sheets>
<xr:revisionPtr revIDLastSave = "0" documentId = "10_ncr:8100000_{2DB04D48-B75D-47CA-B49A-7D110058603D}" xr6:coauthVersionLast = "34" xr6:coauthVersionMax = "34" xr10:uidLastSave = "{00000000-0000-0000-0000-000000000000}" /></workbook>
The difference is:
Why is this sentence written?
Function to create, write and save file:
function TZertifikat.ZertifikatNachExcel(aErneutErstellen: Boolean; var aExcelDateiPfad: String): Boolean;
var
tmpxls: TXlsFile;
tmpZeileFrei, tmpSpaltenIndex: integer;
XF, i, y, j: integer;
Zelle: TCellValue;
AdresseZelle: TCellAddress;
tmpLieferdatum: string;
tmpExcelFilePfad: string;
tmpVorlageGefunden: Boolean;
Ini: TInifile;
gefunden: Boolean;
ListeChargenNr: TSTringList;
SpChargenNr: Integer;
ChNrVorhanden: Boolean;
tmpProdDatum: TDate;
tmpString: string;
tmpWertTyp: Integer;
tmpWertReal: Double;
tmpWertBool: Boolean;
tmpWertString: string;
tmpWertAnaNr700: Double;
tmpWertAnaNr701: Double;
tmpSpalteAnaNr700: Integer;
tmpSpalteAnaNr701: Integer;
addrAnaNr700: TCellAddress;
addrAnaNr701: TCellAddress;
tmpSpaltenName700: string;
tmpSpaltenName701: string;
okWeiter: Boolean;
ChargenNrSchonDa: Boolean;
LieferscheinNrSchonDa: Boolean;
tmpCHNrInExcel: TDateTime;
ms: TMemoryStream;
tmpPfad: string;
begin
Result := False;
try
aExcelDateiPfad := '';
// Zertifikat-Versand als Excel-File per EMail prüfen
if ExcelAlsEmail then
begin
// Excel-Vorlage im Kundenartikel vorhanden?
tmpExcelFilePfad := '';
tmpExcelFilePfad := PfadExcelDatei;
tmpVorlageGefunden := False;
tmpVorlageGefunden := FileExists(tmpExcelFilePfad);
if tmpVorlageGefunden then
begin
try
ms := TMemoryStream.Create;
ms.LoadFromFile(tmpExcelFilePfad);
ms.position := 0;
tmpxls := TXlsFile.Create(true);
tmpxls.Open(ms);
try
if tmpxls.SheetCount > 0 then
begin
for y := 1 to tmpxls.SheetCount do
begin
tmpxls.ActiveSheet := y;
// INI-Datei erzeugen und speichern
ExcelIni := TStringList.Create;
Excelini.Clear;
Excelini.Text := ExcelZuordnungIni;
ExcelIni.SaveToFile(ExtractFilepath(Application.ExeName) + 'TmpExcelIni.ini');
ini := TIniFile.Create(ExtractFilepath(Application.ExeName) + 'TmpExcelIni.ini');
//-------
//Neue Zeile Finden :
tmpZeileFrei := 4;
try
tmpZeileFrei := ini.ReadInteger('Zuordnung' + IntToStr(y), 'Startzeile', 4);
except
tmpZeileFrei := 4;
end;
gefunden := false;
while not gefunden do
begin
tmpZeileFrei := tmpZeileFrei + 1;
if (tmpxls.GetCellValue(tmpZeileFrei, 1).IsEmpty) then
gefunden := true;
end;
//Alle bisherigen Chargennummern suchen
SpChargenNr := 9999;
ListeChargenNr := TStringList.Create;
ini.ReadSection('Zuordnung', ListeChargenNr);
for i := 1 to ListeChargenNr.Count do
begin
if UPPERCASE(ini.ReadString('Zuordnung' + IntToStr(y), ListeChargenNr[i - 1], '')) =
'CHARGENNUMMER' then
begin
SpChargenNr := i;
break;
end;
end;
ListeChargenNr.Clear;
ListeChargenNr.Free;
ChNrVorhanden := false;
if SpChargenNr <> 9999 then
begin
for i := tmpZeileFrei - 1 downto 1 do
begin
if (tmpxls.GetCellValue(i, SpChargenNr) = ChargenNr.AsString) and (ChargenNr.AsString <> '') then
begin
ChNrVorhanden := true;
end;
end;
end;
if (aErneutErstellen = True) then
begin
okWeiter := True;
end;
if okWeiter then
begin
//IN EXCEL SCHREIBEN
for i := 1 to 500 do
begin
if ini.ValueExists('Zuordnung' + IntToStr(y), inttostr(i)) then
begin
tmpString := '';
tmpString := ini.ReadString('Zuordnung' + IntToStr(y), inttostr(i), '');
//leeres Feld
if (tmpString = '') or (Uppercase(tmpString) = 'N') then
tmpxls.SetCellValue(tmpZeileFrei, i, '')
else if (Uppercase(tmpString) = 'DATUM') then
tmpxls.SetCellValue(tmpZeileFrei, i, date)
else if (Uppercase(tmpString) = 'DATUM_GEMAHLEN') then
begin
tmpProdDatum := Produktionsdatum;
if tmpProdDatum > 0 then
tmpxls.SetCellValue(tmpZeileFrei, i, DateToStr(tmpProdDatum))
else
tmpxls.SetCellValue(tmpZeileFrei, i, '');
end
else if (Uppercase(tmpString) = 'DATUM_GELIEFERT') then
tmpxls.SetCellValue(tmpZeileFrei, i, DateToStr(Lieferdatum.AsDate))
else if (Uppercase(tmpString) = 'CHARGENNUMMER') then
tmpxls.SetCellValue(tmpZeileFrei, i, ChargenNr.AsString)
else if (Uppercase(tmpString) = 'ARTIKELNUMMER') then
tmpxls.SetCellValue(tmpZeileFrei, i, ArtikelNr.AsString)
else if (Uppercase(tmpString) = 'ARTIKELNAME') then
tmpxls.SetCellValue(tmpZeileFrei, i, ArtikelName.AsString)
else if (Uppercase(tmpString) = 'LIEFERSCHEINNUMMER') then
tmpxls.SetCellValue(tmpZeileFrei, i, LieferscheinNr)
else if (Uppercase(tmpString) = 'KUNDENBESTELLNUMMER') then
tmpxls.SetCellValue(tmpZeileFrei, i, KuBestellNr.AsString)
else if (Uppercase(tmpString) = 'VERLADEDATUM') then
tmpxls.SetCellValue(tmpZeileFrei, i, DateToStr(Verladedatum))
else if (Uppercase(tmpString) = 'P/L') then
// xls.SetCellValue(tmpZeileFrei, i, TFormula.Create('=' + tmpSpaltenName700 + IntToStr(tmpZeileFrei) + '/N' + tmpSpaltenName701 + IntToStr(tmpZeileFrei)))
tmpxls.SetCellValue(tmpZeileFrei, i, TFormula.Create('=M' + IntToStr(tmpZeileFrei) + '/ N' + IntToStr(tmpZeileFrei)))
else if (Uppercase(tmpString) = 'MHD') then
begin
tmpProdDatum := Produktionsdatum;
tmpProdDatum := IncMonth(tmpProdDatum, MHDMonate);
tmpxls.SetCellValue(tmpZeileFrei, i, DateToStr(tmpProdDatum))
end
else if (Uppercase(tmpString) = 'AUSGEBLENDET') then
begin
if ExcelTyp = 0 then
tmpxls.SetColHidden(i, true)
else if ExcelTyp = 1 then
tmpxls.SetColHidden(i, true);
end
else if IstInteger(tmpString) then
begin
tmpquery.Close;
tmpquery.SQL.Clear;
tmpquery.SQL.Add('SELECT Typ,WertReal,WertBool,WertString FROM ZertifikateAna');
tmpquery.SQL.Add('WHERE AnaNr=' + tmpString);
tmpquery.SQL.Add('AND ID_Zertifikat=' + Inttostr(FID.AsInteger));
tmpquery.Open;
if tmpquery.RecordCount = 0 then
begin
if ExcelTyp = 0 then
tmpxls.SetCellValue(tmpZeileFrei, i, '')
else if ExcelTyp = 1 then
tmpxls.SetColHidden(i, true);
end
else
begin
tmpWertReal := 0.0;
tmpWertAnaNr700 := 0.0;
tmpWertAnaNr701 := 0.0;
tmpWertBool := False;
tmpWertString := '';
tmpWertTyp := tmpquery.FieldByName('Typ').AsInteger;
tmpWertReal := tmpquery.FieldByName('WertReal').AsFloat;
tmpWertBool := tmpquery.FieldByName('WertBool').AsBoolean;
tmpWertString := tmpquery.FieldByName('WertString').AsString;
if tmpString = '700' then
begin
tmpSpaltenName700 := Dialog_ExcelDefinator.GetSpaltenName(i);
end;
if tmpString = '701' then
begin
tmpSpaltenName701 := Dialog_ExcelDefinator.GetSpaltenName(i);
end;
if ExcelTyp = 1 then
tmpxls.SetColHidden(i, false);
case tmpWertTyp of
0: tmpxls.SetCellValue(tmpZeileFrei, i, tmpWertReal);
1:
begin
if tmpWertBool then
tmpxls.SetCellValue(tmpZeileFrei, i, 'JA')
else
tmpxls.SetCellValue(tmpZeileFrei, i, 'Nein')
end;
else
tmpxls.SetCellValue(tmpZeileFrei, i, tmpWertString);
end;
end;
tmpquery.Close;
end
//Text
else
tmpxls.SetCellValue(tmpZeileFrei, i, tmpString);
end;
end;
tmpxls.Save(ms);
ms.SaveToFile(tmpExcelFilePfad);
ini.Free;
DeleteFile(PWideChar(ExtractFilepath(Application.ExeName) + 'TmpExcelIni.ini'));
ExcelIni.Free;
end;
end;
end;
finally
FreeAndNil(tmpxls);
end;
finally
ms.Free;
end;
if okWeiter then
begin
if (tmpExcelFilePfad <> '') then
begin
aExcelDateiPfad := tmpExcelFilePfad;
end;
end;
end;
end;
Result := okWeiter;
except
on e:exception do
BtbFehler('ZertifikatNachExcel', e);
end;
end;
Thanks in advance
Best regards
Irina Hornung