使用ByteScout Spreadsheet在excel文件中写入多个工作表

时间:2014-07-22 15:11:30

标签: c# excel spreadsheet

我有几个DataTable对象,我想将它们写入一个excel文件但是各种工作表。

我正在使用bytescout.spreadsheet来处理Excel文件。

如何使用此工具和C#编写多个表格到excel文件?

1 个答案:

答案 0 :(得分:1)

阅读手册:http://bytescout.com/products/developer/spreadsheetsdk/bytescoutxls_working_with_worksheets_in_xls_document.html

using System;
using System.Collections.Generic;
using System.Text;
using Bytescout.Spreadsheet;
namespace Worksheets
{

internal class Program
{
    private static void Main(string[] args)
    {
    // Create new Spreadsheet
        Spreadsheet document = new Spreadsheet();
      // Add worksheets
        Worksheet worksheet1 = document.Workbook.Worksheets.Add("Demo worksheet 1");
        Worksheet worksheet2 = document.Workbook.Worksheets.Add("Demo worksheet 2");
      // Get worksheet by name
        Worksheet worksheetByName = document.Workbook.Worksheets.ByName("Demo worksheet 2");
      // Set cell values
        worksheet1.Cell(0, 0).Value = "This is Demo worksheet 1";
        worksheetByName.Cell(0, 0).Value = "This is Demo worksheet 2";
        // Save document
        document.SaveAs("Worksheets.xls");
    }
}