读书人

把入指的EXCEL中,该如何解决

发布时间: 2012-01-19 00:22:27 作者: rapoo

把入指的EXCEL中
我用的是asp.net 找了很多都是c#是代,不知如何成asp.net
我在想把表里到一excel里。 但打excel都有。如何理。各位忙。

Private Sub cmdExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdExport.Click

Dim xApp = New Excel.Application
Dim xBook As Excel.Workbook
Dim xSheet As New Excel.Worksheet
xBook = xApp.Workbooks.Add( "..\Scripts\A.xls ")
xSheet = xBook.Worksheets(1)
xSheet.Cells(2, 3) = Format(Now(), "yyyy-MM-dd ")
xApp.Visible = True

End Sub
在vb.net 是上面的法。不知asp.net是怎的

[解决办法]
StreamWriter w = new StreamWriter("test.xls");
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Rows[i].ItemArray.Length; j++)
{
char c = (char)9;
temp = dt.Rows[i][j].ToString();
temp = temp.Replace(@"""", @"""""");
w.Write('"');
w.Write(temp);
w.Write('"');
w.Write(c);
//w.Write(',');
}
w.WriteLine("");
}
w.Flush();
w.Close();

读书人网 >asp.net

热点推荐