Support,
Currently we use Aspose.Cells to export a ASP.NET page to Excel but the format is very plain with no styling. How can we keep the styling?
Here is what we do in the Load_Complete event:
'Get HTML of the page
Dim oStringWriter As New StringWriter()
Dim oHtmlTextWriter As New HtmlTextWriter(oStringWriter)Render(oHtmlTextWriter)
Dim reader = New StringReader(oStringWriter.ToString())
Dim strContent As String = reader.ReadToEnd.ToString()
'Let strip off all the header info
strContent = Mid(strContent, InStr(strContent, “–>”) + 4)strContent = StripTags(strContent)
'Get rid of tags
strContent = Replace(strContent, “ ”, “”)
strContent = Replace(strContent, “”, “”)
strContent = Replace(strContent, “”, “”)
strContent = Replace(strContent, “”, “”)strContent = Trim(strContent)
'Set the values for splitting the data into an array
Dim arg() As String = {vbCrLf, vbLf}Dim objArrayList As New ArrayList(strContent.Split(arg, StringSplitOptions.RemoveEmptyEntries))
'Loop through removing items that are blank
For iLoop As Integer = objArrayList.Count - 1 To 0 Step -1
If Trim(objArrayList(iLoop).ToString()) = “” Then
objArrayList.RemoveAt(iLoop)
End If
Next'Excel
Dim workbook As Workbook = New Workbook()
Dim sheet As Worksheet = workbook.Worksheets(0)'Put the data into the spreadsheet
sheet.Cells.ImportArrayList(objArrayList, 1, 0, True)'Get Worksheet Cells Collection
Dim cell As Cells = sheet.Cells'Set Style
For i As Integer = 0 To cell.Count<span style="color:green;">'Increase the width of First Column Width</span> cell.SetColumnWidth(0, 150) <span style="color:green;">'Increase the height of first row</span> cell.SetRowHeight(0, 36) <span style="color:green;">'Trim the extra spaces</span> cell(i, 0).Value = Trim(cell(i, 0).Value) <span style="color:green;">'Get Style</span> <span style="color:blue;">Dim</span> style <span style="color:blue;">As</span> <span style="color:#2b91af;">Style</span> = cell(i, 0).GetStyle() <span style="color:green;">'Make Cell's Text wrap</span> style.IsTextWrapped = <span style="color:blue;">True</span> <span style="color:green;">'Set Style</span> cell(i, 0).SetStyle(style)
Next
'Save
workbook.Save(HttpContext.Current.Response, “Export.xls”, Aspose.Cells.ContentDisposition.Attachment, New XlsSaveOptions(Aspose.Cells.SaveFormat.Excel97To2003))HttpContext.Current.Response.End()
Thanks,
Cean