| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,16 @@ | |||
| 1 | + <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | + <classpath> | ||
| 3 | + <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/> | ||
| 4 | + <classpathentry kind="src" path="src/main/java" including="**/*.java"/> | ||
| 5 | + <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/> | ||
| 6 | + <classpathentry kind="output" path="target/classes"/> | ||
| 7 | + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
| 8 | + <classpathentry kind="var" path="M2_REPO/org/apache/poi/poi/3.9/poi-3.9.jar"/> | ||
| 9 | + <classpathentry kind="var" path="M2_REPO/commons-codec/commons-codec/1.5/commons-codec-1.5.jar"/> | ||
| 10 | + <classpathentry kind="var" path="M2_REPO/org/apache/poi/poi-ooxml/3.9/poi-ooxml-3.9.jar"/> | ||
| 11 | + <classpathentry kind="var" path="M2_REPO/org/apache/poi/poi-ooxml-schemas/3.9/poi-ooxml-schemas-3.9.jar"/> | ||
| 12 | + <classpathentry kind="var" path="M2_REPO/org/apache/xmlbeans/xmlbeans/2.3.0/xmlbeans-2.3.0.jar"/> | ||
| 13 | + <classpathentry kind="var" path="M2_REPO/stax/stax-api/1.0.1/stax-api-1.0.1.jar"/> | ||
| 14 | + <classpathentry kind="var" path="M2_REPO/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar"/> | ||
| 15 | + <classpathentry kind="var" path="M2_REPO/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar"/> | ||
| 16 | + </classpath> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,29 @@ | |||
| 1 | + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 2 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 3 | + <modelVersion>4.0.0</modelVersion> | ||
| 4 | + | ||
| 5 | + <groupId>com.hmkcode</groupId> | ||
| 6 | + <artifactId>java-excel-poi</artifactId> | ||
| 7 | + <version>1.0-SNAPSHOT</version> | ||
| 8 | + <packaging>jar</packaging> | ||
| 9 | + | ||
| 10 | + <name>java-excel-poi</name> | ||
| 11 | + <url>http://maven.apache.org</url> | ||
| 12 | + | ||
| 13 | + <properties> | ||
| 14 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 15 | + </properties> | ||
| 16 | + | ||
| 17 | + <dependencies> | ||
| 18 | + <dependency> | ||
| 19 | + <groupId>org.apache.poi</groupId> | ||
| 20 | + <artifactId>poi</artifactId> | ||
| 21 | + <version>3.9</version> | ||
| 22 | + </dependency> | ||
| 23 | + <dependency> | ||
| 24 | + <groupId>org.apache.poi</groupId> | ||
| 25 | + <artifactId>poi-ooxml</artifactId> | ||
| 26 | + <version>3.9</version> | ||
| 27 | + </dependency> | ||
| 28 | + </dependencies> | ||
| 29 | + </project> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,59 @@ | |||
| 1 | + package com.hmkcode.poi; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | + import java.io.File; | ||
| 5 | + import java.io.FileNotFoundException; | ||
| 6 | + import java.io.FileOutputStream; | ||
| 7 | + import java.io.IOException; | ||
| 8 | + import java.util.Date; | ||
| 9 | + | ||
| 10 | + import org.apache.poi.hssf.util.CellReference; | ||
| 11 | + import org.apache.poi.openxml4j.exceptions.InvalidFormatException; | ||
| 12 | + import org.apache.poi.ss.usermodel.Cell; | ||
| 13 | + import org.apache.poi.ss.usermodel.CellStyle; | ||
| 14 | + import org.apache.poi.ss.usermodel.CreationHelper; | ||
| 15 | + import org.apache.poi.ss.usermodel.DateUtil; | ||
| 16 | + import org.apache.poi.ss.usermodel.Row; | ||
| 17 | + import org.apache.poi.ss.usermodel.Sheet; | ||
| 18 | + import org.apache.poi.ss.usermodel.Workbook; | ||
| 19 | + import org.apache.poi.ss.usermodel.WorkbookFactory; | ||
| 20 | + import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + public class AppRead | ||
| 24 | + { | ||
| 25 | + public static void main( String[] args ) | ||
| 26 | + { | ||
| 27 | + Workbook wb = null; | ||
| 28 | + try { | ||
| 29 | + wb = WorkbookFactory.create(new File("workbook.xlsx")); | ||
| 30 | + } catch (InvalidFormatException e) { | ||
| 31 | + e.printStackTrace(); | ||
| 32 | + } catch (IOException e) { | ||
| 33 | + e.printStackTrace(); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + Sheet sheet = wb.getSheetAt(0); | ||
| 37 | + | ||
| 38 | + //********************************* | ||
| 39 | + Cell cell = sheet.getRow(0).getCell(0); | ||
| 40 | + double numberVal = cell.getNumericCellValue(); | ||
| 41 | + System.out.println("Row: 0 - Column: 0 = "+numberVal); | ||
| 42 | + //----------------------------- | ||
| 43 | + cell = sheet.getRow(0).getCell(1); | ||
| 44 | + String stringVal = cell.getStringCellValue(); | ||
| 45 | + System.out.println("Row: 0 - Column: 1 = "+stringVal); | ||
| 46 | + //----------------------------- | ||
| 47 | + cell = sheet.getRow(0).getCell(2); | ||
| 48 | + Date dateVal = cell.getDateCellValue(); | ||
| 49 | + System.out.println("Row: 0 - Column: 2 = "+dateVal); | ||
| 50 | + //----------------------------- | ||
| 51 | + cell = sheet.getRow(0).getCell(3); | ||
| 52 | + boolean booleanVal = cell.getBooleanCellValue(); | ||
| 53 | + System.out.println("Row: 0 - Column: 3 = "+booleanVal); | ||
| 54 | + //----------------------------- | ||
| 55 | + | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,68 @@ | |||
| 1 | + package com.hmkcode.poi; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | + import java.io.FileNotFoundException; | ||
| 5 | + import java.io.FileOutputStream; | ||
| 6 | + import java.io.IOException; | ||
| 7 | + import java.util.Date; | ||
| 8 | + import org.apache.poi.ss.usermodel.Cell; | ||
| 9 | + import org.apache.poi.ss.usermodel.CellStyle; | ||
| 10 | + import org.apache.poi.ss.usermodel.CreationHelper; | ||
| 11 | + import org.apache.poi.ss.usermodel.Row; | ||
| 12 | + import org.apache.poi.ss.usermodel.Sheet; | ||
| 13 | + import org.apache.poi.ss.usermodel.Workbook; | ||
| 14 | + import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + public class AppWrite | ||
| 18 | + { | ||
| 19 | + public static void main( String[] args ) | ||
| 20 | + { | ||
| 21 | + | ||
| 22 | + //1. Create a new Workbook | ||
| 23 | + Workbook wb = new XSSFWorkbook(); | ||
| 24 | + | ||
| 25 | + //2. Create a new sheet | ||
| 26 | + Sheet sheet = wb.createSheet("sheet 1"); | ||
| 27 | + | ||
| 28 | + //3. Create a row | ||
| 29 | + Row row = sheet.createRow((short) 0); | ||
| 30 | + | ||
| 31 | + //4. Create cells | ||
| 32 | + | ||
| 33 | + //4.1 number cell | ||
| 34 | + row.createCell(0).setCellValue(1); | ||
| 35 | + //4.2 text | ||
| 36 | + row.createCell(1).setCellValue("Text"); | ||
| 37 | + | ||
| 38 | + //4.3 date cell | ||
| 39 | + CreationHelper createHelper = wb.getCreationHelper(); | ||
| 40 | + CellStyle cellStyle = wb.createCellStyle(); | ||
| 41 | + cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("m/d/yy h:mm")); | ||
| 42 | + Cell cell = row.createCell(2); | ||
| 43 | + cell.setCellValue(new Date()); | ||
| 44 | + cell.setCellStyle(cellStyle); | ||
| 45 | + | ||
| 46 | + //4.4 boolean cell | ||
| 47 | + row.createCell(3).setCellValue(true); | ||
| 48 | + | ||
| 49 | + //5. create excel file | ||
| 50 | + FileOutputStream fileOut; | ||
| 51 | + try { | ||
| 52 | + | ||
| 53 | + fileOut = new FileOutputStream("workbook.xlsx"); | ||
| 54 | + wb.write(fileOut); | ||
| 55 | + fileOut.close(); | ||
| 56 | + | ||
| 57 | + } catch (FileNotFoundException e) { | ||
| 58 | + e.printStackTrace(); | ||
| 59 | + } catch (IOException e) { | ||
| 60 | + e.printStackTrace(); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + System.out.println( "File created!" ); | ||
| 64 | + | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + | ||
| 68 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments