HtmlText To Excel
2012-03-06 17:27
197 查看
public static string GetHtmlText(int id)
{
StringBuilder builder = new StringBuilder();
builder.Append("<style>");
builder.Append("#chris{ font-family:Times New Roman;font-style:normal;;vertical-align:middle;}");
builder.Append(".title1{ font-family:Arial;text-align:center;vertical-align:middle;font-size:22pt;}");
builder.Append(".title2{ text-align:center;vertical-align:middle;font-size:14pt;height:45}");
builder.Append(".title3{ font-family:Arial;text-align:center;vertical-align:middle;font-size:10pt;height:35}");
builder.Append(".content{ font-family:Arial;text-align:center;font-size:10pt;background:yellow;}");
builder.Append(".comment{ font-family:Arial;text-align:center;font-size:10pt;}");
builder.Append("</style>");
builder.Append("<table id=\"chris\" border=\"1\">");
builder.Append("<tr><td colspan=\"15\" class=\"title1\"><strong>XXXXXXXXXXXXXXXXXX</strong></td></tr>");
builder.Append("<tr class=\"title2\">");
builder.Append("<td>xxx</td>");
builder.Append("<td>xxx</td>");
builder.Append("<td>xxx</td>");
builder.Append("<td colspan=\"4\">xxx</td>");
builder.Append("<td>xxx</td>");
builder.Append("<td>xxx</td>");
builder.Append("<td>xxx</td>");
builder.Append("<td>xxx</td>");
builder.Append("<td>xxx</td>");
builder.Append("<td>xxx</td>");
builder.Append("<td>xxx</td>");
builder.Append("<td>xxx</td>");
builder.Append("<tr class=\"title3\">");
builder.Append("<td style=\"background:#CC99FF\">xxx</td>");
builder.Append("<td style=\"background:#7FFF00\">xxx</td>");
builder.Append("<td style=\"background:#33CCCC\">xxx</td>");
builder.Append("<td>xxx</td>");
builder.Append("<td>xxx</td>");
builder.Append("<td>xxx</td>");
builder.Append("<td>xxx</td>");
builder.Append("<td></td>");
builder.Append("<td></td>");
builder.Append("<td></td>");
builder.Append("<td></td>");
builder.Append("<td></td>");
builder.Append("<td></td>");
builder.Append("<td></td>");
builder.Append("<td></td>");
builder.Append("</tr>");
Log entity = null;
new Report().CreateLog(id,out entity);
builder.Append("<tr class=\"content\">");
builder.Append(string.Format("<td align=\"left\">{0}</td>", entity.xxx));
builder.Append(string.Format("<td align=\"left\">{0}</td>", entity.xxx));
builder.Append(string.Format("<td align=\"left\">{0}</td>", entity.xxx));
builder.Append(string.Format("<td align=\"left\">{0}</td>", entity.xxx));
builder.Append(string.Format("<td align=\"left\">{0}</td>", entity.xxx));
builder.Append(string.Format("<td align=\"right\">{0}</td>", entity.xxx));
builder.Append(string.Format("<td align=\"right\">{0}</td>", entity.xxx));
builder.Append(string.Format("<td align=\"left\">{0}</td>", entity.xxx));
builder.Append(string.Format("<td align=\"right\">{0:M/d/yyyy}</td>", entity.xxx));
builder.Append(string.Format("<td align=\"center\">{0}</td>", entity.xxx));
builder.Append(string.Format("<td align=\"right\">{0:M/d/yyyy}</td>", entity.xxx));
builder.Append(string.Format("<td align=\"right\">{0}</td>", entity.xxx));
builder.Append(string.Format("<td align=\"right\">{0}</td>", entity.xxx));
builder.Append(string.Format("<td align=\"right\">{0}</td>", entity.xxx));
builder.Append(string.Format("<td align=\"left\">{0}</td>", entity.xxx));
builder.Append("</tr>");
builder.Append("</table>");
return builder.ToString();
}
public static void HtmlTextToExcel(string htmltext, HttpResponse response, string filename)
{
response.Clear();
response.Buffer = true;
response.AppendHeader("Content-Disposition", "attachment;filename=" + filename + ".xls");
response.ContentEncoding = System.Text.Encoding.Default;
response.ContentType = "application/ms-excel";
response.Write(htmltext);
response.Flush();
response.End();
}
public static void ExportToZip(string fullname, HttpResponse response, string taskid)
{
FileStream fileStream = new FileStream(fullname, FileMode.Open);
long fileSize = fileStream.Length;
byte[] fileBuffer = new byte[fileSize];
fileStream.Read(fileBuffer, 0, (int)fileSize);
fileStream.Close();
response.Clear();
response.Buffer = true;
response.Charset = "gb2321";
response.AppendHeader("Content-Disposition", "attachment;filename=" + taskid + ".zip");
response.ContentEncoding = System.Text.Encoding.UTF8;
response.ContentType = "application/zip";
response.AddHeader("Content-Length", fileSize.ToString());
response.BinaryWrite(fileBuffer);
response.Flush();
response.End();
}
相关文章推荐
- WordExcelToHtml
- 打开pdf ppt word excel chm html text 文件的intent
- How to make text of an html checkbox clickable (like ASP.NET control)
- drupal6中使用drupal_html_to_text方法过滤替换html超文本代码
- [Cocoa]convert html to plain text
- SharePoint 2010: Export User Profile Properties to a Text File or Excel using PowerShell
- Export Data from GridView to Excel, Word, HTML with C#
- From HTML to Excel
- Read a Text File with VBA in Excel, and Write the Text to a Spreadsheet
- The Easy Way to Extract Useful Text from Arbitrary HTML 从HTML文件中抽取正文的简单方案
- ...append HTML Text to a TWebbrowser Document?
- Convert EXCEL TO HTML
- Android执行打开文件(PDF,PPT,WORD,EXCEL,CHM,HTML,TEXT,AUDIO,VIDEO)的总结
- How to get html text in a Flex Alert panel.
- From HTML to Excel
- Exporting from Crystal Reports to PDF, Word, Excel and HTML
- How to Add a Dotted Underline Beneath HTML Text
- illegal to have multiple occurrences of 'contentType' with different values (old: [text/html; chars
- illegal to have multiple occurrences of contentType with different values (old: text/html; charset=
- HtmlToText c#