我正在尋找一種方式導出一個Excel電子表格的方式,使每個單元格中有多個值。ASP.NET Excel導出
我目前使用HtmlTextWriter類將Html寫入Excel內容類型格式,但它會爲相應的Row內的每個值創建一個新的Cell。
例如,目前寫出 行1:RowTitle值1 行2:值2 行3:值3
我想是在一行中寫的一切。 ROW1:RowTitle值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();
感謝。
你試過用OleDb嗎? – 2012-08-14 04:35:02