zoukankan      html  css  js  c++  java
  • java org 写excel

    package com.csland.workflow.business;

    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFCell;
    import org.apache.poi.hssf.usermodel.*;
    import java.io.FileOutputStream;

    public class ylexcel {
      public ylexcel() {

      }

      private static void createCellTitle(HSSFWorkbook wb, HSSFRow row, int column,
                                          String value) {
        HSSFCell cell = row.createCell((short)column);

        HSSFCellStyle cellStyle = wb.createCellStyle();
        cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);

        HSSFFont font = wb.createFont();
        font.setFontHeightInPoints( (short) 11);   ;
        font.setFontName("宋体");
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        cellStyle.setFont(font);

        cell.setCellStyle(cellStyle);

        cell.setCellValue(value);

      }

      private static void createFile(String outputFile) {
        try {
          // Create a New XL Document
          HSSFWorkbook wb = new HSSFWorkbook();
          // Make a worksheet in the XL document created
          HSSFSheet sheet = wb.createSheet();
          // Create row at index zero ( Top Row)

          HSSFRow row = sheet.createRow( (short) 0);
          for (int i = 0; i < 10; i++) {
            createCellTitle(wb, row, i, "gisoracle" + i);

          }

          // The Output file is where the xls will be created
          FileOutputStream fOut = new FileOutputStream(outputFile);
          // Write the XL sheet
          wb.write(fOut);
          fOut.flush();
          // Done Deal..
          fOut.close();
          System.out.println("File Created ..");

        }
        catch (Exception e) {
          System.out.println("!!BANG!! xlCreate() : " + e);
        }
      }

      public static void ylb(String ym) {
        System.out.println("poi");
        createFile("c:/test.xls");
        System.out.println("==============");

      }

    }

  • 相关阅读:
    2017寒假作业二 汇总随笔
    2017寒假作业一
    UVA 1601 POJ 3523 The Morning after Halloween 【双向BFS】【A*】 (好题)
    UVA 10570 Meeting with Aliens 【枚举+结论题】
    UVA 1614 Hell on the Markets 【贪心+结论题】
    UVA 10603 Fill【BFS】
    Codevs 1288 埃及分数 【IDA*】
    UVA 11212 Editing a Book 【IDA*】
    UVA 11624 Fire! 【特殊BFS】
    UVA 1599 Ideal Path 【两次BFS+贪心】 (好题)
  • 原文地址:https://www.cnblogs.com/gisoracle/p/1515327.html
Copyright © 2011-2022 走看看