博客
关于我
NPOI初级教程
阅读量:794 次
发布时间:2023-02-17

本文共 3161 字,大约阅读时间需要 10 分钟。

NPOI Excel????????????

NPOI? Necessary POI ????????????? Excel ??? Java ??????? Java ???? Excel ?????????????? NPOI ?? Excel ?????????????? Excel ?????? Excel ????????????


Excel ??????

??? NPOI ?? Excel ?????????? Excel ????????

  • Excel 2007 (.xlsx)??? XSSFWorkbook ? XSSFSheet ??

    XSSFWorkbook wb; XSSFSheet sh;
  • Excel 2003 (.xls)??? HSSFWorkbook ? HSSFSheet ??

    HSSFWorkbook wk = new HSSFWorkbook();ISheet sheet = wk.CreateSheet("Images");

???? Excel ??

??????? Excel ????????

HSSFWorkbook wb; FileStream file;file = new FileStream(filepath, FileMode.Open, FileAccess.Read);wb = new HSSFWorkbook(file);file.Close();// ?????ISheet image_sheet = wk.GetSheet("Images");ISheet confidence_sheet = wk.GetSheet("Confidence");// ?? Excel ????????int rowsCount = image_sheet .PhysicalNumberOfRows;int colsCount = image_sheet .GetRow(0).PhysicalNumberOfCells;

??? Excel ??

???????? Excel ????????

var workBook = new HSSFWorkbook();ISheet sheet = null;sheet = workBook.CreateSheet("sheet1");// ???????IRow row = sheet.CreateRow(0);row.CreateCell(0).SetCellValue("??");row.CreateCell(1).SetCellValue("??");// ??????workBook.SetActiveSheet(0);// ????string filePath=@"test.xls";using (FileStream fs = new FileStream(filePath, FileMode.Create)){    workBook.Write(fs);}

??????????

????????????????????

ICellStyle cellstyle = workbook.CreateCellStyle();cellstyle.VerticalAlignment = VerticalAlignment.Center;cellstyle.Alignment = HorizontalAlignment.Center;cell.CellStyle = cellstyle;// ????????????????for (int i = 0; i <= columnsCount; i++) {    sheet.AutoSizeColumn(i);}// ?????????????for (int i = 0; i < 15; i++) {    int columnWidth = sheet.GetColumnWidth(i) / 256;    for (int rowNum = 4; rowNum < 6 + rowsCount; rowNum++) {        IRow currentRow;        if (sheet.GetRow(rowNum) == null) {            currentRow = sheet.CreateRow(rowNum);        } else {            currentRow = sheet.GetRow(rowNum);        }        if (currentRow.GetCell(i) != null) {            ICell currentCell = currentRow.GetCell(i);            int length = Encoding.Default.GetBytes(currentCell.ToString()).Length;            if (columnWidth < length) {                columnWidth = length;            }        }        sheet.SetColumnWidth(i, columnWidth * 350);    }}

?????? Excel

?????? Java ?????? Excel ??????

using NPOI.HSSF.UserModel;using NPOI.SS.UserModel;using NPOI.XSSF.UserModel;using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp1 {    class Program {        static void Main(string[] args) {            using (FileStream fs = File.OpenRead(@"F:\PycharmWorkPlace\test2excel\test.xlsx")) {                XSSFWorkbook wb = new XSSFWorkbook(fs);                ISheet sh = wb.GetSheet("Sheet1");                Console.WriteLine(sh.GetRow(0).GetCell(0).StringCellValue);                Console.ReadLine();            }        }    }}

????

  • ?????Excel 2007 ? Excel 2003 ?????????????????? Excel ?????????? XSSFWorkbook ? HSSFWorkbook??
  • ????????????????????????????????????????
  • ?????????? Excel ????????????? DateTime ? Boolean?????????????????
  • ?????????????? NPOI ??????? Excel ????????????

    转载地址:http://nejfk.baihongyu.com/

    你可能感兴趣的文章
    node防xss攻击插件
    查看>>
    noi 1996 登山
    查看>>
    noi 7827 质数的和与积
    查看>>
    NOI-1.3-11-计算浮点数相除的余数
    查看>>
    NOI2010 海拔(平面图最大流)
    查看>>
    NOIp2005 过河
    查看>>
    NOIP2011T1 数字反转
    查看>>
    NOIP2014 提高组 Day2——寻找道路
    查看>>
    noip借教室 题解
    查看>>
    NOIP模拟测试19
    查看>>
    NOIp模拟赛二十九
    查看>>
    Vue3+element plus+sortablejs实现table列表拖拽
    查看>>
    Nokia5233手机和我装的几个symbian V5手机软件
    查看>>
    non linear processor
    查看>>
    Non-final field ‘code‘ in enum StateEnum‘
    查看>>
    none 和 host 网络的适用场景 - 每天5分钟玩转 Docker 容器技术(31)
    查看>>
    None还可以是函数定义可选参数的一个默认值,设置成默认值时实参在调用该函数时可以不输入与None绑定的元素...
    查看>>
    NoNodeAvailableException None of the configured nodes are available异常
    查看>>
    Vue.js 学习总结(16)—— 为什么 :deep、/deep/、>>> 样式能穿透到子组件
    查看>>
    nopcommerce商城系统--文档整理
    查看>>