Hi,
I need to copy a range to new sheet with following details
All columns and values
Merged columns, Style and values as is
Range columns style
to a new sheet then convert it to HTML
Thank You
Lijo George
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"test.xlsx");
Worksheet sheet1 = workbook.Worksheets[0];
//Add a new sheet
Worksheet sheet2 = workbook.Worksheets.Add("new sheet");
//Scource cell range
CellRange sourceCell = sheet1.Range["C3:H16"];
int startRI = sourceCell.Row;
int startCI = sourceCell.Column;
int rowCount = sourceCell.RowCount;
int columnCount = sourceCell.ColumnCount;
//Destination cellrange
CellRange destCell = sheet2.Range[startRI, startCI, startRI + rowCount - 1, startCI + columnCount - 1];
//Copy cells
sourceCell.Copy(destCell, false, true);
for (int i = startRI; i < startRI + rowCount; i++)
{
for (int j = startCI; j < startCI + columnCount; j++)
{
//Merge cells
if (sourceCell[i, j].HasMerged)
{
CellRange area = sourceCell[i, j].MergeArea;
if (i == area.Row && j == area.Column)
{
sheet2.Range[area.Row, area.Column, area.Row + area.RowCount - 1, area.Column + area.ColumnCount - 1].Merge();
}
}
//Copy style, row height, column width and border style
destCell[i, j].Style = sourceCell[i, j].Style;
destCell[i, j].RowHeight = sourceCell[i, j].RowHeight;
destCell[i, j].ColumnWidth = sourceCell[i, j].ColumnWidth;
destCell[i, j].Borders[BordersLineType.EdgeBottom].LineStyle = sourceCell[i, j].Borders[BordersLineType.EdgeBottom].LineStyle;
destCell[i, j].Borders[BordersLineType.EdgeLeft].LineStyle = sourceCell[i, j].Borders[BordersLineType.EdgeLeft].LineStyle;
destCell[i, j].Borders[BordersLineType.EdgeRight].LineStyle = sourceCell[i, j].Borders[BordersLineType.EdgeRight].LineStyle;
destCell[i, j].Borders[BordersLineType.EdgeTop].LineStyle = sourceCell[i, j].Borders[BordersLineType.EdgeTop].LineStyle;
}
}
//convert to html
sheet2.SaveToHtml("output.html");