Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 重新排序没有互操作对象的Excel表_C#_Excel_Export_Export To Excel_Web Based - Fatal编程技术网

C# 重新排序没有互操作对象的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,而不使用互操作。 我想您谈论的是一

我正在用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 );
    }
}

谢谢-这正是我想要的。