以XML的形式输出EXCEL
XML里就是些Table标签,当然包括写 rowspan colspan 等等。
现在输出EXCEL 2007 到一定位置时候出现(目前我的错位行在2213行),错列现象。
多数据导出都有这个问题。
经调试:输出的数据是没有问题的。请高手指点这一现象。有必要我附图上来。谢谢各位!
XML里就是些Table标签,当然包括写 rowspan colspan 等等。
现在输出EXCEL 2007 到一定位置时候出现(目前我的错位行在2213行),错列现象。
多数据导出都有这个问题。
经调试:输出的数据是没有问题的。请高手指点这一现象。有必要我附图上来。谢谢各位!
不过往回倒时就- -
最好把你错的图发出来看看,不然不好说
这种方法本身还是html,只是excel兼容html才能在Excel里显示的
另存的时候有2种xml,换另外一种表格xml
怎么意思?可以在详细点么?由于XML文件太多。我发不了给你们,郁闷。
我建立了一个一般处理程序(.ashx)文件,包含: public void ProcessRequest(HttpContext context)
{
string dataKey = context.Request["datakey"] != null ? context.Request["datakey"] : ""; SortedList<string, string> excelData = context.Application["ExcelData"] as SortedList<string, string>; if (dataKey == "" || excelData == null)
{
context.Response.Write("导出数据已失效!");
context.Response.End();
}
context.Response.Clear();
context.Response.Buffer = true;
context.Response.Charset = "UTF8";
context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("Excel导出数据.xls", System.Text.Encoding.UTF8));
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.ContentType = "application/ms-excel";
context.Response.Write(excelData[dataKey]); excelData.Remove(dataKey);
context.ApplicationInstance.CompleteRequest(); }
private string ExportExcelData(string template, string templateHandler, JsonArray data)
{
XmlDocument templateDoc = new XmlDocument(); templateDoc.Load(HttpContext.Current.Server.MapPath("../Export/Template/" + template + ".xml")); MethodInfo method = typeof(ExportService).GetMethod(templateHandler); if (method != null)
method.Invoke(null, new object[] { templateDoc, data });
XmlNodeList cols = templateDoc.SelectNodes("//td[@class='field']"); foreach (object obj in data)
{
JsonObject dataRow = obj as JsonObject; XmlElement row = templateDoc.CreateElement("tr"); templateDoc.SelectSingleNode("//table").AppendChild(row); foreach (XmlNode col in cols)
{
XmlElement cell = templateDoc.CreateElement("td"); row.AppendChild(cell); string field = (col as XmlElement).GetAttribute("id"); if (dataRow.Contains(field))
{
cell.InnerText = dataRow[field] != null ? dataRow[field].ToString() : "";
}
}
} if (HttpContext.Current.Application["ExcelData"] == null)
HttpContext.Current.Application["ExcelData"] = new SortedList<string, string>(); string dataKey = Guid.NewGuid().ToString(); (HttpContext.Current.Application["ExcelData"] as SortedList<string, string>)
.Add(dataKey, templateDoc.OuterXml); return dataKey;
}