我正在寻找一种导出 Excel 电子表格的方法,使得每行的一个单元格中有多个值。
我目前正在使用 HtmlTextWriter 类将 Html 写入 Excel 内容类型格式,但它会为相应行中的每个值创建一个新单元格。
例如,它当前写出第 1 行:RowTitle Value1 第 2 行:Value2 第 3 行:Value3
我想要的是将所有内容写在一行中。第 1 行:行标题 值 1 值 2 值 3 行 2:
这可能吗 - 有没有人有任何指示?
我目前的代码如下:
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
Response.AddHeader("content-disposition", "filename=Compare" + fileName + ".xls");
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.ClearControls(tblComparison);
tblComparison.RenderControl(oHtmlTextWriter);
// Embed style rules here so that when opening the file in Excel separately, the styling will stay in place
// and not be dependent on an external css file.
Response.Write(@"
<head>
<title>Compare</title>
<style>
#tblComparison { empty-cells:show;border-collapse:collapse;border:none; }
#tblComparison tr td { vertical-align:top;text-align:center;padding:0px 5px 2px 8px;border-right:1px solid #094A8C;border-bottom:1px dotted #6699FF;font-size:.7em }
#tblComparison tr td.header { text-align:right;font-weight:bold }
#tblComparison tr td.header span.note { text-align:right;font-weight:normal;color:#094A8C; }
#tblComparison tr td div.itrs { display:none }
#tblComparison tr td textarea { width:20em }
#tblComparison tr td textarea.objective { height:5em;font-size:.9em }
#tblComparison tr td select { width:200px;font-size:1em }
#tblComparison tr td textarea.comments { height:10em;font-size:.9em }
#tblComparison tr td textarea.multiline { height:10em;font-size:.9em }
#tblComparison tr td.requested textarea.comments,
#tblComparison tr td.requested textarea.objective { background-color:#F2F7FB;border:1px solid gray }
#tblComparison tr td.requested input { font-size:1em;background-color:#F2F7FB;border:1px solid gray }
#tblComparison tr .existRequested { background-color:#52697B; color:White;}
div { font-size: 1em }
</style>
</head>
");
Response.Write(oStringWriter.ToString());
Response.End();
提前致谢。