Want to extract a table from excel using apsose cell and write it in aspose word

@Raghul214,

See the following sample code for your reference.
e.g.,
Sample code:

using (var fstream = new FileStream("e:\\test2\\TestExport.xlsx", FileMode.Open))
{
	// Instantiate a Workbook object that represents the existing Excel file
	var workbook = new Workbook(fstream);
	
	var sheet = workbook.Worksheets["Sheet1"];

	workbook.Worksheets.ActiveSheetIndex = sheet.Index;

    var range1 = sheet.Cells.CreateRange(0, 0, 3, 3); 
    var range2 = sheet.Cells.CreateRange("G1:J3");

    
    sheet.PageSetup.PrintArea = range1.Address + "," + range2.Address;

	// Save the Excel file to HTML
	workbook.Save("e:\\test2\\out1.html", new HtmlSaveOptions
	{
		ExportImagesAsBase64 = true,
		ExportPrintAreaOnly = true,
		ExportHiddenWorksheet = false,
		ExportActiveWorksheetOnly = true
	});
} 

Yes Hello @amjad.sahi I tried the above but it was not in a continuous way like I can see its way apart
I just want it together

@Raghul214,

Could you please share your input Excel file, the output HTML (generated by Aspose.Cells), and a sample (runnable) code to evaluate your issue? Also, please share the expected output HTML file that you want to achieve. We will look into it soon.

PS. Please zip the files before attaching them here.

Input
image.png (174.9 KB)
Output
image.png (111.8 KB)
But I want like
image.png (169.5 KB)
Since I am not able to upload excel file I added screenshot

@Raghul214,

Thanks for the screenshots.

I do not think this is possible automatically when you specify multiple print areas, unless you paste your other range manually with the first range of cells. You can try your scenario in MS Excel manually and you will notice that the other range will be separated and won’t be merged in the print preview unless you merge it manually using copy/paste operations. In short, if you need to merge ranges, you may need to cut or copy/paste the ranges. See the document with example code for your reference. Once you have merged/inserted the other range with your first range, then you may set the print area covering all the data of both ranges. Now render to HTML using the code segment and it will work for the purpose.

Hmm ok I will try that and thank you for responding early😊

@Raghul214,

You are welcome.

1 Like

Hello @amjad.sahi I am able to achieve this but one is like if i have content in a cell which is not shown completely only the thing which is visible is getting shown in html so i did autofitrow and column its working but still some part is Missing how to retrieve the entire content of all cells in a range

And also here if I want to copy and paste only cells which is not hidden how to achieve that

@Keerthana_K_R,

Could you please share your sample (runnable) code and template Excel file (please zip the file first) to show the issue, we will check it soon.

This behavior is same with MS Excel, you may check it in MS Excel manually. You may evaluate if a row is hidden via Row.IsHidden attribute (you may browse rows in a loop) and then remove each hidden hidden row in code before inserting or cut/copy paste the range.

Example File.zip (29.3 KB)
This is the document and I am trying to print it in html from A3 till M10 but see the second row first column its missing letter M and start printing from -100…
Let me add the screenshot of output aswell
image.png (8.9 KB)

Yes @amjad.sahi I am aware about this approach but wanted to check if there were some other ease approach. That’s fine already I am able to achieve with ishidden attribute Thanks for that😊

@Raghul214,

Thanks for the sample file and details.

After an initial test, I was able to reproduce the issue as you mentioned by using your template Excel file and following sample code. I found some letters (e.g., M in second row) are not visible even after using/calling Worksheet.AutoFitColumns when rendering to HTML.

using (var fstream = new FileStream("e:\\test2\\Example File.xlsm", FileMode.Open))
{
    // Instantiate a Workbook object that represents the existing Excel file
    var workbook = new Workbook(fstream);

    var sheet = workbook.Worksheets[0];

    workbook.Worksheets.ActiveSheetIndex = sheet.Index;

    var range = sheet.Cells.CreateRange("A3:M10");


    sheet.PageSetup.PrintArea = range.Address;

    sheet.AutoFitColumns();

    // Save the Excel file to HTML
    workbook.Save("e:\\test2\\out1.html", new HtmlSaveOptions
    {
        ExportImagesAsBase64 = true,
        ExportPrintAreaOnly = true,
        ExportHiddenWorksheet = false,
        ExportActiveWorksheetOnly = true
    });
}

We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-55838

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like

It is nice to know that you have implemented it to accomplish the task.

Yes Thank you for that :blush:

@Keerthana_K_R
You are welcome. If you have any questions, please feel free to contact us.

@Raghul214

We are pleased to inform you that your issue has been resolved. The fix will be included in an upcoming release (Aspose.Cells v24.6) that we plan to release in the first half of June 2024. You will be notified when the next version is released.

Attached is the fixed result for your reference:
output.zip (3.7 KB)

Yes sure, @Eric.wang Thanks for the update :blush:

@Keerthana_K_R,

You are welcome. We will keep you posted with updates (once available).

The issues you have found earlier (filed as CELLSNET-55838) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi