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.

Fri Sep 04, 2020 10:16 am

Hi,

I would like to know if Spire.XLS for .Net can convert Excel to HTML from a specific range cells or using a range name?
Language: C#

For example,

Step 1

Workbook "Report" => Sheet "Report 1" => Cell Range Name "Table 1"
or
Workbook "Report" => Sheet "Report 1" => Cell Range using First Row, First Column, Last Row, Last Column

Step 2

Finally,
Convert it HTML and Return the function with HTML body content
like

return string sheet.SaveToHtml("sample.html");

Thank you in advance
Lijo

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

Mon Sep 07, 2020 7:30 am

Hello,

Thanks for your inquiry.
You can first copy the cell range you want to convert into the new worksheet, and then convert the new worksheet to HTML. Below is the code for your reference.
Code: Select all
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"XXXX.xlsx");

            Worksheet sheet1 = workbook.Worksheets[0];
            //Add a new sheet
            Worksheet sheet2 = workbook.Worksheets.Add("new sheet");

            //destination range
            CellRange cells = sheet2.Range["A1:D5"];

            //specific range cells
            CellRange cellRange = sheet1.Range["A1:D5"];
            cellRange.Copy(cells, false, true);

            ////named range
            //CellRange namedRange = workbook.NameRanges["test"].RefersToRange as CellRange;
            //namedRange.Copy(cells, false, true);         

            //convert to html
            sheet2.SaveToHtml("out.html");


Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Tue Sep 29, 2020 3:55 am

Hello,

Greetings from E-iceblue.
How is your issue now? Could you please give us some feedback at your convenience?

Sincerely
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Return to Spire.XLS