Hello,
Thank you for your inquiry.
Regarding your question about merged cells, we would like to inform you that when merging cells, only the first cell contains a value, while the remaining cells are considered empty by default. If you need to retrieve the values from the merged cells, excluding the first cell, you can utilize the following code snippet:
- Code: Select all
Workbook workbook = new Workbook();
workbook.LoadFromFile("input.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Gets a collection of merged cells in a worksheet
CellRange[] ranges= worksheet.MergedCells;
//Traverse the merge cell collection
foreach (CellRange range in ranges)
{
//Gets the display text for the merged cell
string displayText = range.DisplayedText;
//Gets the region of the merged cells
CellRange cellRange = range.MergeArea;
//Gets the specified cell
CellRange outRange = worksheet["A3"];
//Traverse all cells of the merged cell
for (int i = 0; i < cellRange.CellsCount;i++)
{
CellRange ranges1 = cellRange.CellList[i];
//Determines whether the specified cell is in the merge cell range
if (outRange.RangeAddress.Equals(ranges1.RangeAddress))
{
//Assigns the obtained display text to the text in the specified cell
outRange.Text = displayText;
Console.WriteLine(outRange.DisplayedText);
}
}
}
Sincerely,
Annika
E-iceblue support team