How can I write to an Excel spreadsheet using Linq?

后端 未结 6 412
独厮守ぢ
独厮守ぢ 2020-12-28 10:01

I\'m writing an app where I need to retrieve some rows from a DB and dump them into an Excel spreadsheet. I\'m using Linq to retrieve these rows.

Is it possible to

6条回答
  •  一向
    一向 (楼主)
    2020-12-28 10:09

    Take a look at this Excel Data Object Provider. I haven't personally used the writing functionality of it and I adapted the reading support to allow for ordinal (as well as named) column identifiers, but it may be a step in the right direction. Keep in mind that you cannot write or read from XLSX files unless Excel 2003+ is installed on the target machine; standard XLS files will work on any Windows box though.

    My adapted version with ordinal columns can be found here. You may find it necessary/helpful to implement that in the current version (at the above link) if you decide to use the code. My version is a hybrid of features from the version 2.0 and 2.5- it has all of the reading functionality (with some 2.5 upgrades), but no writing. Oh- and unlike either version 2.0 or 2.5, my version doesn't require that the first sheet in the Excel document be named "Sheet1".

    Hope that helps!

提交回复
热议问题