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,
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,
test.xls attached.
Thank you for reply.
Hi Hassan,