C#或.net中用NPIO要怎样才能导出2007以上的Excel(.xlsx)?
2个回答
展开全部
public static void DownData(DataView dvData, string fileName)
{
StringBuilder strBd = new StringBuilder(EXCELHTMLHEAD + "<table x:str><tr>");
int cols = dvData.Table.Columns.Count;
for (int j = 0; j < cols; j++)
strBd.Append("<td>" + dvData.Table.Columns[j].Caption + "</td>");
strBd.Append("</tr>");
for (int i = 0; i < dvData.Count; i++)
{
strBd.Append("<tr>");
for (int j = 0; j < cols; j++)
strBd.Append("<td>" + Lixiang.Common.HtmlToTxt(Convert.ToString(dvData[i][j])) + "</td>");
strBd.Append("</tr>");
}
strBd.Append("</table></body></html>");
DownData(strBd.ToString(), fileName);
}
public const string EXCELHTMLHEAD = @"<html xmlns:o='urn:schemas-microsoft-com:office:office'
xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>
<head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>
<x:Name>ExportData</x:Name><x:WorksheetOptions><x:Selected/></x:WorksheetOptions>
</x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->
</head><body>";
{
StringBuilder strBd = new StringBuilder(EXCELHTMLHEAD + "<table x:str><tr>");
int cols = dvData.Table.Columns.Count;
for (int j = 0; j < cols; j++)
strBd.Append("<td>" + dvData.Table.Columns[j].Caption + "</td>");
strBd.Append("</tr>");
for (int i = 0; i < dvData.Count; i++)
{
strBd.Append("<tr>");
for (int j = 0; j < cols; j++)
strBd.Append("<td>" + Lixiang.Common.HtmlToTxt(Convert.ToString(dvData[i][j])) + "</td>");
strBd.Append("</tr>");
}
strBd.Append("</table></body></html>");
DownData(strBd.ToString(), fileName);
}
public const string EXCELHTMLHEAD = @"<html xmlns:o='urn:schemas-microsoft-com:office:office'
xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>
<head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>
<x:Name>ExportData</x:Name><x:WorksheetOptions><x:Selected/></x:WorksheetOptions>
</x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->
</head><body>";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询