Skip to content

Commit f3dd823

Browse files
DYN-6515 OpenXML ExportXML Bug Fix (#16206)
1 parent 76df374 commit f3dd823

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Libraries/DSOfficeUtilities/OpenXmlHelper.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,21 @@ internal static bool Write(string filePath, string sheetName, object[][] data, i
163163
}
164164

165165
Row row;
166+
//This case is when we need to append a new row at the end of the spreadsheet
166167
if (rowsIndex >= rows.Count)
167168
{
168169
// Add a new row to the end
169170
row = new Row() { RowIndex = currentRowIndex };
170171
sheetData.AppendChild(row);
171172
}
173+
//This case is when there are empty rows before or in between the populated rows
172174
else if (rows[rowsIndex].RowIndex > currentRowIndex)
173175
{
174176
// Add a new row before this one
175177
row = new Row() { RowIndex = currentRowIndex };
176-
sheetData.InsertBefore(rows[rowsIndex], row);
178+
179+
//This is the method definition - InsertBefore(newChild, referenceChild), so we need to pass row as first argument
180+
sheetData.InsertBefore(row, rows[rowsIndex]);
177181
}
178182
else
179183
{
@@ -608,6 +612,14 @@ private static void SetCellValue(object value, Cell cell, SharedStringTable shar
608612
{
609613
// The string is not in the table, so we add it
610614
sharedStringTable.AppendChild(new SharedStringItem(new Text((string)value)));
615+
616+
//Means that the current (row, column) is probably empty so we should start from 0
617+
if (sharedStringTable.Count == null)
618+
{
619+
sharedStringTable.Count = 0;
620+
sharedStringTable.UniqueCount = 0;
621+
}
622+
611623
index = (int)sharedStringTable.Count.Value;
612624
// Yes, you need to update these manually
613625
sharedStringTable.Count++;

0 commit comments

Comments
 (0)