C# 重新排序没有互操作对象的Excel表
我正在用C#编写一个程序,需要按其中一列对工作表重新排序。目前,我无法使用Office Interop对象来控制文件,因此我一直在使用Excel Data Reader读取它(http://exceldatareader.codeplex.com/)为了读入文件,因为我的输出总是在csv、tsv或SQL表中。关于如何将数据表保存为excel,或者是否存在在不使用互操作的情况下对其重新排序的命令,有什么想法吗?有一种方法可以通过web网格将数据表保存为excel,而不使用互操作。 我想您谈论的是一个应用程序,因此必须引用C# 重新排序没有互操作对象的Excel表,c#,excel,export,export-to-excel,web-based,C#,Excel,Export,Export To Excel,Web Based,我正在用C#编写一个程序,需要按其中一列对工作表重新排序。目前,我无法使用Office Interop对象来控制文件,因此我一直在使用Excel Data Reader读取它(http://exceldatareader.codeplex.com/)为了读入文件,因为我的输出总是在csv、tsv或SQL表中。关于如何将数据表保存为excel,或者是否存在在不使用互操作的情况下对其重新排序的命令,有什么想法吗?有一种方法可以通过web网格将数据表保存为excel,而不使用互操作。 我想您谈论的是一
System.Web
库
守则:
// Create the DataGrid and perform the databinding
var myDataGrid = new System.Web.UI.WebControls.DataGrid();
myDataGrid.HeaderStyle.Font.Bold = true;
myDataGrid.DataSource = myDataTable;
myDataGrid.DataBind();
string myFile = "put the name here with full path.xls"
var myFileStream = new FileStream( myFile, FileMode.Create, FileAccess.ReadWrite );
// Render the DataGrid control to a file
using ( var myStreamWriter = new StreamWriter( myFileStream ) )
{
using (var myHtmlTextWriter = new System.Web.UI.HtmlTextWriter(myStreamWriter ))
{
myDataGrid .RenderControl( myHtmlTextWriter );
}
}
谢谢-这正是我想要的。