把數據輸入指寫的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();