C#或.net中用NPIO要怎样才能导出2007以上的Excel(.xlsx)?
发布网友
发布时间:2022-04-24 05:33
我来回答
共2个回答
热心网友
时间:2023-11-01 05:44
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>";
热心网友
时间:2023-11-01 05:44
好像NPOI不支持导出2007及更高版本的格式
可以考虑用EPPLUS
参考下面的博客:
http://blog.csdn.net/accountwcx/article/details/8144970
热心网友
时间:2023-11-01 05:44
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>";
热心网友
时间:2023-11-01 05:44
好像NPOI不支持导出2007及更高版本的格式
可以考虑用EPPLUS
参考下面的博客:
http://blog.csdn.net/accountwcx/article/details/8144970
热心网友
时间:2023-11-01 05:44
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>";
热心网友
时间:2023-11-01 05:44
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>";
热心网友
时间:2023-11-01 05:44
好像NPOI不支持导出2007及更高版本的格式
可以考虑用EPPLUS
参考下面的博客:
http://blog.csdn.net/accountwcx/article/details/8144970
热心网友
时间:2023-11-01 05:44
好像NPOI不支持导出2007及更高版本的格式
可以考虑用EPPLUS
参考下面的博客:
http://blog.csdn.net/accountwcx/article/details/8144970