We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to have the same conversion result html to xlsx as in your online tool

hello,
when I use your online tool to convert this html file I have this result, but when I did it locally in my machine using aspose.cells for c# I have an other result.Preformatted textonligneTestNeed.zip (7.7 KB)
onligneTestxlsxResult.zip (19.1 KB)

locallyConversionTestResult.zip (18.9 KB)

what I hope, is avoid that fisrt table column take the same width as the bloc before the table.
thank you for your help.

@Benabdallah_Sabti,

I did test your scenario/case using our latest version/fix, i.e., Aspose.Cells for .NET v21.6 (please try it if you are not already using it) with the following sample code and it works same to the online tool results:
e.g.
Sample code:

Workbook workbook = new Workbook("e:\\test2\\onligneTestNeed.html");
workbook.Save("e:\\test2\\out1.xlsx");

Please find attached the output file for your reference. I guess you might be using some different code segment to produce the output file via Aspose.Cells APIs. In case you still find any issue, kindly do share your sample code (runnable) to reproduce the issue, we will check it soon.
files1.zip (19.7 KB)

thank you for your quick reply.
I use the same code as you and I obtain the same result as online tool also, but I need to use AutoFitColumns();
and when I use it like this :
Workbook workbook = new Workbook(“e:\test2\onligneTestNeed.html”);
workbook.Worksheets[0].AutoFitColumns();
workbook.Save(“e:\test2\out1.xlsx”);
it’s give me a bad result , (I need to apply AutoFitColumns anly to tabe colomns).
thanks

@Benabdallah_Sabti,
Well it seems that there is no direct way to auto fit columns of the table only however if you device some criteria to find the first and last cell of first table, you may modify your code to use the overload of the function AutoFitColumns() as demonstrated in the following example.

Workbook workbook = new Workbook(@"onligneTestNeed.html");
workbook.Worksheets[0].AutoFitColumns(26,0,140,11);
workbook.Save(@"onligneTest_Output.xlsx");

thanks a lot @ahsaniqbalsidiqui @Amjad_Sahi , I try to do the same (I try it and it’s work ),but
now I have to find a way how to get those four parameters ( 26,0,140,11) , because the html at input is html generated dynamically.

@Benabdallah_Sabti,

Please note, as you were using Worksheet.AutoFitColumns() method (without specifying specific range/area to auto-fit), so, it was considering all the cells area. That’s why you are getting first column more broader and extended.

You need to devise your own code based on specific criteria to evaluate those parameters. One approach can be you find the row/col index of the first table header and specify those parameters accordingly. See the following sample code for your reference:
e.g.
Sample code:

Workbook workbook = new Workbook("e:\\test2\\onligneTestNeed.html");
            //You could get the row/col index of table starting row index by finding some column header e.g. cell containing "Brand Name" or other item. 
            string header = "Brand Name";
            Cell fcell = workbook.Worksheets[0].Cells.Find(header, null);
            int row = fcell.Row;
            int col = fcell.Column;
            //evaluate other parameters
            int lastRow = workbook.Worksheets[0].Cells.MaxDataRow -5;//I have done this deliberately as the last cell also has long string, so want to skip/avoid from the bottom when auto-fitting columns.
            int lastCol = workbook.Worksheets[0].Cells.MaxDataColumn;

            //Now auto-fit columns starting from specific row/col indices.
            workbook.Worksheets[0].AutoFitColumns(row, col, lastRow, lastCol);
            workbook.Save("e:\\test2\\out1.xlsx");

Hope, this helps a bit.

thank you , but since it a dynamic doc with different localisation (spanish, french, …ect) it’s not easy to hard coded it like that, but I have an other question in this way.
is there any way to find the first cell with solid border?

@Benabdallah_Sabti,
You may please try the following code to find first cell with solid border.

Workbook workbook = new Workbook(@"onligneTestNeed.html");
Worksheet worksheet = workbook.Worksheets[0];


Style style = workbook.CreateStyle();

// Specify the style for searching
FindOptions options = new FindOptions();

style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
options.Style = style;

Cell nextCell = null;

do
{
    nextCell = worksheet.Cells.Find(null, nextCell, options);
    if (nextCell == null)
        break;
    Console.WriteLine($"It is found at Row:{nextCell.Row} and Column:{nextCell.Column}");
    break;

} while (true);
workbook.Worksheets[0].AutoFitColumns(nextCell.Row, nextCell.Column, 140,11);
workbook.Save(@"onligneTest_Output.xlsx");

@ahsaniqbalsidiqui Thank you , this what I search, I try it , it work this what I need.
Thanks

@Benabdallah_Sabti,
Good to know that your issue is sorted out. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.