0

I have a small program to insert rows in an existing excel file. On certain columns it is formatted a certain way such as centering bold face and Number columns. When I pull data into the excel file from an external source within excel the formatting is preserved. But when I use C# to push data into the excel file the formatting is stripped. Here is the code I am using

using (OleDbConnection conn = new OleDbConnection(string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES"";Jet OLEDB:Engine Type=37", exportPath)))
{
     conn.Open();
     OleDbCommand comm = new OleDbCommand(q, conn);
     comm.Parameters.AddWithValue("@MyNumber", record.MyNumber);
     comm.Parameters.AddWithValue("@Revision", record.RevisionChange);
     comm.ExecuteNonQuery();
}

Any ideas

4

1 回答 1

0

使用 execl 文件时,请避免使用互操作 dll。最好的方法是使用 NPOI dll,以防您需要比简单 sql 更多的功能。

您可以轻松应用字体或任何其他格式。我相信它也会保留任何现有的格式

从codeplex免费下载,包含大量示例

于 2013-04-19T18:20:11.137 回答