Converting html excel file to excel file programmatically

i need to convert html excel to an excel file. this is my code

StreamReader sr = new StreamReader(context.Request.InputStream);
string htmlString = sr.ReadToEnd();

// Write the string to excel file.
StreamWriter file = new StreamWriter(“Test.xls”);
file.WriteLine(htmlString);
file.Close();

HTMLLoadOptions opts = new HTMLLoadOptions(Aspose.Cells.LoadFormat.Html);
Workbook workbook = new Workbook(“Test.xls”, opts);

if i try to save workbook with Excel format (i.e Aspose.Cells.SaveFormat.Excel97To2003), it just Contains some invalid character not real data. this is my code to save excel

workbook.Save(context.Response.OutputStream, Aspose.Cells.SaveFormat.Excel97To2003);

Does Apose.Cells support converting html excel file to excel file programmatically?
Thank you.

Hi Hassan,


Thank you for considering Aspose APIs.

Aspose.Cells APIs support loading HTML file and possible conversion to spreadsheet formats, however, the HTML structure should adhere to the standards outlined by Excel application, that mean, the Aspose.Cells APIs can load HTML with 100% fidelity if it corresponds to the Excel’s specifications. In order to check if your HTML file is a valid candidate for conversion, you should load it with Excel application. If you are getting the correct results in Excel, it should produce similar results with Aspose.Cells APIs.

Moreover, please remove the statements related to StreamWriter for testing purposes and pass the file path location to your said HTML file directly in Workbook constructor to see the results.

Everything work good when i working with html pdf, the problem is DisplayRightToLeft its not working. i thought the problem is in html format but when i trying to open another excel file, DisplayRightToLeft is not working too… Can u help me to fix this problem?

here is my complete code :

public void ProcessRequest(HttpContext context)
{
StreamReader sr = new StreamReader(context.Request.InputStream);
string htmlString = sr.ReadToEnd();

// Write the string to a file.
StreamWriter file = new StreamWriter(“E:/Projects/Modabber/Files/test.xls”);
file.WriteLine(htmlString);
file.Close();

HTMLLoadOptions opts = new
HTMLLoadOptions(Aspose.Cells.LoadFormat.Html);

Workbook workbook = new Workbook(“E:/test.xls”, opts);
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;

sheet.Cells.DeleteBlankRows();
sheet.AutoFitColumns();

// Create the Default Style for group item rows

Style defaultStyle = workbook.Styles[workbook.Styles.Add()];
defaultStyle.Font.Name = “B Mitra”;
defaultStyle.Font.Size = 14;
defaultStyle.HorizontalAlignment = TextAlignmentType.Right;
defaultStyle.VerticalAlignment = TextAlignmentType.Right;
defaultStyle.Borders[BorderType.TopBorder].Color = Color.Black;
defaultStyle.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
defaultStyle.Borders[BorderType.BottomBorder].Color = Color.Black;
defaultStyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
defaultStyle.Borders[BorderType.LeftBorder].Color = Color.Black;
defaultStyle.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
defaultStyle.Borders[BorderType.RightBorder].Color = Color.Black;
defaultStyle.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;

Range defaultStyleRange = cells.CreateRange(0, 0, cells.Rows.Count, cells.Columns.Count);
defaultStyleRange.RowHeight = 25;
defaultStyleRange.ApplyStyle(defaultStyle, new StyleFlag { All = true });


sheet.DisplayRightToLeft = true;
workbook.Save(context.Response.OutputStream, Aspose.Cells.SaveFormat.Html);
context.Response.AddHeader(“Content-Disposition”, “attachment; filename=” + “ExcelName.xls”);
}

Hi,


Thank you for writing back.

We need the test.xls to properly investigate the matter on our side so please share it here so we could check and get back to you with updates in this regard.

test.xls attached.
Thank you for reply.

Hi Hassan,


Thank you for the sample.

I have checked the sample and it appears to be fine when loaded with Excel application. I have also executed your exact code against the latest version of Aspose.Cells for .NET 8.6.1.2 to get the expected results, that is; text renders Right to Left in resultant HTML. Please check the attachment for the HTML file generated on my side. Also attached is the snapshot of the HTML in Internet Explorer 11. Please give a try to the latest version on your end because hopefully it will fix the issue. In case the problem persists, please provide a sample application replicating the issue with latest release (8.6.1.2) along with its dependencies. Moreover, please share the browser details where you are loading the resultant HTML along with a snapshot of the problem.