Bug Description
When a cell is set with an empty string via AsString := '', the generated
sheet1.xml contains <v>-1</v>, which is an invalid sharedStrings index.
Excel reports "已移除的記錄: /xl/worksheets/sheet1.xml 部分的 儲存格資訊"
(Removed records: cell information from sheet1.xml) and silently drops the cells.
Root Cause
In Office4D.Excel.Workbook.pas:
BuildSharedStrings (line 742) intentionally excludes empty strings:
if (Cell.IsString) and (Cell.GetAsString <> '') then
if not Result.Contains(Cell.GetAsString) then
Result.Add(Cell.GetAsString);
But GenerateSheet (line 951) still calls GetSharedStringIndex for empty
strings without checking, so IndexOf returns -1:
const StrIdx = GetSharedStringIndex(SharedStrings, Cell.GetAsString);
SB.Append('<c r="' + CellPair.Key + '"' + StyleAttr +
' t="s"><v>' + IntToStr(StrIdx) + '</v></c>');
Attached File
I've attached C:\Temp\TfrmRpcReqM\xl\worksheets\sheet1.xml (extracted from the broken .xlsx).
sheet1.xml
In this file, find -1 to see:
<c r="E10" t="s"><v>-1</v></c>
<c r="F10" t="s"><v>-1</v></c>
Bug Description
When a cell is set with an empty string via
AsString := '', the generatedsheet1.xmlcontains<v>-1</v>, which is an invalid sharedStrings index.Excel reports "已移除的記錄: /xl/worksheets/sheet1.xml 部分的 儲存格資訊"
(Removed records: cell information from sheet1.xml) and silently drops the cells.
Root Cause
In
Office4D.Excel.Workbook.pas:BuildSharedStrings(line 742) intentionally excludes empty strings:But GenerateSheet (line 951) still calls GetSharedStringIndex for empty
strings without checking, so IndexOf returns -1:
Attached File
I've attached
C:\Temp\TfrmRpcReqM\xl\worksheets\sheet1.xml(extracted from the broken .xlsx).sheet1.xml
In this file, find
-1to see: