Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Sep 22, 2020 6:08 am

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

lijgeorge
 
Posts: 15
Joined: Fri Sep 04, 2020 9:53 am

Tue Sep 22, 2020 9:17 am

Hello,

Thanks for your inquiry.
Could you please provide us with a sample Excel file as well as your desired output? Then we will give you an accurate response. You can upload your files here or sent them to us (support@e-iceblue.com) via email. Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Tue Sep 22, 2020 10:23 am

Hi Rachel,

Thanks you for the quick response, I have emailed to support@e-iceblue.com Id.

Thank You
Lijo George

lijgeorge
 
Posts: 15
Joined: Fri Sep 04, 2020 9:53 am

Wed Sep 23, 2020 3:28 am

Hi Lijo,

Thanks for providing more information via email.
For the first question, sorry our Spire.XLS does not support directly converting the CellRange to HTML, we just support converting a single sheet or the entire workbook to HTML.
As for your second question, you can refer to the following code to copy cell styles and download the latest Spire.XLS Pack(Hotfix) Version:10.9.0 for testing.
Code: Select all
            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");

But regarding “Output is an email” you mentioned in your message, how do you create the email? Are you using our Spire.Email? Please provide more details in this regard to help us investigate further.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.XLS