Export a list of LINQ objects to Excel file

前端 未结 3 605
一整个雨季
一整个雨季 2021-02-10 22:21

From a web application, is there a simple way to export a list of LINQ objects to an Excel file? Are there any good libraries that can do this?

3条回答
  •  孤独总比滥情好
    2021-02-10 22:30

    So, in specifying Excel, you're committing to a row / column paradigm (as opposed to xml, for example). So you'll have to specify how the properties map to columns.

    Beyond that you write to an Excel file using the Ole DB provider. Loop through your objects, generating an INSERT statement for each one using a stringbuilder, and execute that against your sheet. Easy as cake.

提交回复
热议问题