Hi,
Imagine that we've merged column B & C.
If we have 3 texts to add on the line 15, it should be A15, B15 & D15.
Is there a way to move to next column ?
Thanks,
Vincent
public static void AddItem (Worksheet sheet, string[] valueArray)
{
int firstRow = GetFirstItemRow(sheet); // Return 16
int newRow = firstRow + 1;
sheet.InsertRow(newRow, 1, InsertOptionsType.FormatAsAfter);
for (int col = 0; col < valueArray.Count(); col++)
{
char colName = (char)('A' + col);
string cellName = colName.ToString() + firstRow.ToString(); // Keep previous line number
//sheet.move
CellRange cell = sheet.Range[cellName];
cell.Text = valueArray[col];
}
}
int firstRow = 16; // Return 16
int newRow = firstRow + 1;
sheet.InsertRow(newRow, 1, InsertOptionsType.FormatAsAfter);
int t = 0;
for (int col = 0; col < valueArray.Count(); col++)
{
char colName = (char)('A' + t);
string cellName = colName.ToString() + firstRow.ToString(); // Keep previous line number
//sheet.move
CellRange cell = sheet.Range[cellName];
if (cell.HasMerged==true)
{
t++;
}
cell.Text = valueArray[col];
t++;
}
int firstRow = 16; // Return 16
int newRow = firstRow + 1;
sheet.InsertRow(newRow, 1, InsertOptionsType.FormatAsAfter);
int t = 0;
for (int col = 0; col < valueArray.Count(); col++)
{
char colName = (char)('A' + t);
string cellName = colName.ToString() + firstRow.ToString(); // Keep previous line number
CellRange cell = sheet.Range[cellName];
if (cell.HasMerged == true)
{
cell.Text = valueArray[col];
while (cell.HasMerged == true)
{
t++;
colName = (char)('A' + t);
cellName = colName.ToString() + firstRow.ToString();
cell = sheet.Range[cellName];
}
}
else
{
cell.Text = valueArray[col];
t++;
}
}
wb.SaveToFile("result.xlsx", ExcelVersion.Version2010);
sheet.InsertRow(newRow, 1, InsertOptionsType.FormatAsAfter);
public static void DuplicateStyle (Worksheet sheet, int sourceLine, int destinationLine)
{
int t = 0;
for (int col = 0; col < 25; col++)
{
char colName = (char)('A' + t);
string sourceCellName = colName.ToString() + sourceLine.ToString();
string destinationCellName = colName.ToString() + destinationLine.ToString();
CellRange sourceCell = sheet.Range[sourceCellName];
CellRange destinationCell = sheet.Range[destinationCellName];
if (sourceCell.HasMerged == true)
{
destinationCell.NumberFormat = sourceCell.NumberFormat;
destinationCell.HorizontalAlignment = sourceCell.HorizontalAlignment;
destinationCell.VerticalAlignment = sourceCell.VerticalAlignment;
while (sourceCell.HasMerged == true)
{
t++;
colName = (char)('A' + t);
sourceCellName = colName.ToString() + sourceLine.ToString();
sourceCell = sheet.Range[sourceCellName];
}
}
else
{
destinationCell.Style = sourceCell.Style;
destinationCell.NumberFormat = sourceCell.NumberFormat;
destinationCell.HorizontalAlignment = sourceCell.HorizontalAlignment;
destinationCell.VerticalAlignment = sourceCell.VerticalAlignment;
t++;
}
}
}
sheet.InsertRow(newRow, 1, InsertOptionsType.FormatAsBefore);