Git.Storage.Common/Excel/NPOIExcel.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/*******************************************************************************
* Copyright (C) Git Corporation. All rights reserved.
*
* Author: 微软
* Create Date: 2014-11-07 22:36:34
*
* Description: Git.Framework
* www.baidu.com
* Revision History:
* Date Author Description
* 2014-11-07 22:36:34 微软
*********************************************************************************/
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using Git.Framework.DataTypes;
using Git.Framework.DataTypes.ExtensionMethods;
using NPOI.SS.Util;
using NPOI.HSSF.Util;
namespace Git.Storage.Common.Excel
{
public class NPOIExcel
{
private string _title;
private string _sheetName;
private string _filePath;
public NPOIExcel(string title, string sheetName, string filePath)
{
this._title = title;
this._sheetName = sheetName;
this._filePath = filePath;
}
/// <summary>
/// 导出到Excel
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public bool ToExcel(DataTable table)
{
FileStream fs = new FileStream(this._filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
IWorkbook workBook = new HSSFWorkbook();
this._sheetName = this._sheetName.IsEmpty() ? "sheet1" : this._sheetName;
ISheet sheet = workBook.CreateSheet(this._sheetName);
//处理表格标题
IRow row = sheet.CreateRow(0);
row.CreateCell(0).SetCellValue(this._title);
sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, table.Columns.Count - 1));
row.Height = 500;
ICellStyle cellStyle = workBook.CreateCellStyle();
后面还有 53 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
