Posted 15 May 2025, 7:18 am EST
- Updated 15 May 2025, 7:24 am EST
Hi,
Yes, you can safely add your own custom JSON properties inside the .sjs package. However, the product will ignore any unknown properties and only parse the fields it is bound to. So, your metadata - used for tracking or highlighting changes - will not cause load failures or validation errors, as long as the file remains structurally sound.
However, we recommend you write your custom logic for comparing two workbooks in DsExcel.NET as the comparison logic can be a bit too broad and you can write the logic specific to your comparison requirements. You can refer to the below code snippet that illustrates the comparison of two workbooks and rewrite the cell text as per the screenshot:
Workbook originalWorkbook = new();
originalWorkbook.Open("book1.sjs");
Workbook secondWorkbook = new();
secondWorkbook.Open("book2.sjs");
Workbook resultWorkbook = new();
resultWorkbook.Open("book1.sjs"); // base it off the original
for (int i = 0; i < originalWorkbook.Worksheets.Count; i++)
{
IRange usedRange = originalWorkbook.Worksheets[i].GetUsedRange();
for (int row = usedRange.Row; row <= usedRange.LastRow; row++)
{
for (int col = usedRange.Column; col <= usedRange.LastColumn; col++)
{
string originalText = originalWorkbook.Worksheets[i].Cells[row, col].Text;
string newText = secondWorkbook.Worksheets[i].Cells[row, col].Text;
if (!string.IsNullOrEmpty(originalText) && !string.Equals(originalText, newText))
{
IRange resultCell = resultWorkbook.Worksheets[i].Cells[row, col];
resultCell.Clear(); // clear existing content
IRichText richText = resultCell.RichText;
ITextRun oldRun = richText.Add(originalText);
oldRun.Font.Color = System.Drawing.Color.Green;
oldRun.Font.Strikethrough = true;
ITextRun newRun = richText.Add(newText);
newRun.Font.Color = System.Drawing.Color.Red;
newRun.Font.Underline = UnderlineType.Single;
}
}
}
}
resultWorkbook.Save("book3.xlsx");
You can further refer to the attached code sample that uses the above code snippet and generates the required results (see below).
Additionally, the development team also requires the following details to implement a workbook compartor:
What values need to be compared - cell values, text, styles, etc?
Do you also need to compare row height and column widths?
How to handle situations where the sheets in the two workbooks are different?
How to store different comparison results?
Please share a detailed overview of the above scenarios as the comparison is a bit broader concept for the Workbooks and will help us to implement the same in the required direction.
Please feel free to reach out if you encounter any further issues or require additional guidance.
Regards,
Prabhat Sharma.
CompareWorkbooks.zip