
excel
要将ASP.NET网站中的数据导出到
excel文件中,可以使用Microsoft Office Interop组件。以下是一个简单的示例:csharpusing System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using Microsoft.Office.Interop.
excel;using Microsoft.Office.Interop.
excel.Coerce;using Microsoft.Office.Interop.
excel.Workbook;public static void ExportTo
excel(string connectionString, string fileName) { // Create a new
excel application using (var
excelApp = new Application()) { // Create a new workbook var workbook = new Workbook(
excelApp); // Connect to the
Database var connection = new ConnectionStrings().Open(connectionString); var connectionSource = new ConnectionSource(connection); var worksheet = workbook.Worksheets.Add("Sheet1"); // Loop through all rows in the
Database and add them to the worksheet var rowCount = connectionSourceRodCount; for (int i = 1; i