Common/ToExcel.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
namespace Common
{
public class ToExcel
{
/// <summary>
/// 导出Excel
/// </summary>
/// <param name="mydt"></param>
public static void DataToExcel(DataTable mydt, string fileName, Page page)
{
string sheetName = fileName;
if (mydt != null)
{
StringWriter sw = new StringWriter();
sw.WriteLine("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
sw.WriteLine("<head>");
sw.WriteLine("<!--[if gte mso 9]>");
sw.WriteLine("<xml>");
sw.WriteLine(" <x:ExcelWorkbook>");
sw.WriteLine(" <x:ExcelWorksheets>");
sw.WriteLine(" <x:ExcelWorksheet>");
sw.WriteLine(" <x:Name>" + sheetName + "</x:Name>");
sw.WriteLine(" <x:WorksheetOptions>");
sw.WriteLine(" <x:Print>");
sw.WriteLine(" <x:ValidPrinterInfo />");
sw.WriteLine(" </x:Print>");
sw.WriteLine(" </x:WorksheetOptions>");
sw.WriteLine(" </x:ExcelWorksheet>");
sw.WriteLine(" </x:ExcelWorksheets>");
sw.WriteLine("</x:ExcelWorkbook>");
sw.WriteLine("</xml>");
sw.WriteLine("<![endif]-->");
sw.WriteLine("</head>");
sw.WriteLine("<body>");
sw.WriteLine("<table>");
sw.WriteLine(" <tr>");
for (int i = 0; i < mydt.Columns.Count; i++)
{
sw.WriteLine(" <td align=center>" + mydt.Columns[i].ColumnName.ToString() + "</td>");
}
sw.WriteLine(" </tr>");
foreach (DataRow dr in mydt.Rows)
{
sw.WriteLine(" <tr>");
for (int i = 0; i < mydt.Columns.Count; i++)
{
if (mydt.Columns[i].DataType.Name.ToString() == "Decimal" || mydt.Columns[i].DataType.Name.ToString() == "Int32")
{
后面还有 41 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
