对于给定的Excel文件(此处极客), 则需要在其中创建表格。
步骤如下:
创建一个JAVA Maven项目
在pom.xml文件中添加依赖项
<
!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<
dependency>
<
groupId>
org.apache.poi<
/groupId>
<
artifactId>
poi<
/artifactId>
<
version>
3.12<
/version>
<
/dependency>
<
dependency>
<
groupId>
org.apache.poi<
/groupId>
<
artifactId>
poi-ooxml<
/artifactId>
<
version>
3.12<
/version>
<
/dependency>
在javaResource文件夹中创建一个类
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
public class CreateSheet { public static void main(String[] args) throws FileNotFoundException, IOException { //Creating Workbook instances Workbook wb = new HSSFWorkbook();
//An output stream accepts output bytes and sends them to sink. OutputStream fileOut = new FileOutputStream( "Geeks.xlsx" );
//Creating Sheets using sheet object Sheet sheet1 = wb.createSheet( "Array" );
Sheet sheet2 = wb.createSheet( "String" );
Sheet sheet3 = wb.createSheet( "LinkedList" );
Sheet sheet4 = wb.createSheet( "Tree" );
Sheet sheet5 = wb.createSheet( "Dynamic Programing" );
Sheet sheet6 = wb.createSheet( "Puzzles" );
System.out.println( "Sheets Has been Created successfully" );
wb.write(fileOut);
} }
输出如下:
Sheets Has been Created successfully
【使用Apache POI在Java中的Excel文件中创建图纸】这里在geeks.xlsx文件中创建了6张纸:
文章图片
推荐阅读
- 使用Python-Tkinter创建选项卡式小部件
- u盘打开不了了,教您如何修好U盘
- 铭速u盘打开,教您戴尔怎样设置u盘打开
- usb打开,教您如何自制usb打开盘
- 自制u盘,教您如何迅速自制打开盘
- 联想u盘打开,教您联想笔记本怎样设置u盘打开
- u盘打开,教您如何自制u盘打开盘
- 移动u盘加密怎样设置?教您加密办法
- 晨枫u盘维护工具,教您晨枫u盘维护工具