您的位置:首页 > Web前端 > HTML

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();
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: