<pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

          <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

          <p id="bbfd9"></p>

          <p id="bbfd9"><cite id="bbfd9"></cite></p>

            <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

            <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
            <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>

            Java中操作Excel表格方法

            時間:2025-12-14 03:08:56 java語言

            Java中操作Excel表格方法

              引導語:我們都知道Excel 可以進行各種數據的處理、統計分析和輔助決策操作,那么在Java中又是如何操作Excel 表格的呢,以下是百分網小編分享給大家的Java中操作Excel表格方法,歡迎閱讀!

              利用Java Excel API ,下載地址:jexcelapi.rar

              下面給出一段讀取數據的例子代碼:

              /*

              * To change this template, choose Tools | Templates

              * and open the template in the editor.

              */

              package excel;

              import java.io.FileInputStream;

              import java.io.FileNotFoundException;

              import java.io.IOException;

              import java.io.InputStream;

              import java.util.logging.Level;

              import java.util.logging.Logger;

              import jxl.Cell;

              import jxl.Sheet;

              import jxl.Workbook;

              import jxl.read.biff.BiffException;

              /**

              *

              * @author Wei.Liu

              */

              public class Main {

              /**

              * @param args the command line arguments

              */

              public static void main(String[] args) {

              try {

              InputStream is = new FileInputStream("d:\\test.xls");

              jxl.Workbook rwb = Workbook.getWorkbook(is);

              Sheet rs = rwb.getSheet(0);

              /pic/p>

              Cell c00 = rs.getCell(0, 0);

              String strc00 = c00.getContents();

              /pic/p>

              Cell c10 = rs.getCell(1,0);

              String strc10= c10.getContents();

              System.out.println(strc00+" "+c00.getType().toString());

              System.out.println(strc10+" "+c10.getType().toString());

              /pic/p>

              System.out.println(rwb.getNumberOfSheets());

              Sheet [] sheets =rwb.getSheets();

              for(int i=0;i

              System.out.println(rwb.getSheet(i).getName());

              }

              /pic/p>

              System.out.println(rwb.getSheet(0).getColumns());

              /pic/p>

              Cell [] cell = rwb.getSheet(0).getColumn(0);

              /pic/p>

              System.out.println(rwb.getSheet(0).getRows());

              /pic/p>

              Cell [] cell2 = rwb.getSheet(0).getRow(0);

              /pic/p>

              rwb.close();

              } catch (Exception ex) {

              Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

              }

              }

              }

              再給出一段,創建Excel表格的代碼:

              /*

              * To change this template, choose Tools | Templates

              * and open the template in the editor.

              */

              package excel;

              import java.io.File;

              import java.util.logging.Level;

              import java.util.logging.Logger;

              import jxl.Workbook;

              import jxl.write.Label;

              import jxl.write.WritableCellFormat;

              import jxl.write.WritableFont;

              import jxl.write.WritableSheet;

              import jxl.write.WritableWorkbook;

              import jxl.write.Number;

              /**

              *

              * @author Wei.Liu

              */

              public class Main {

              /**

              * @param args the command line arguments

              */

              public static void main(String[] args) {

              try {

              /pic/p>

              WritableWorkbook wwb = Workbook.createWorkbook(new File("d:\\test.xls"));

              /pic/p>

              WritableSheet ws = wwb.createSheet("Liu.Wei",0);

              /pic/p>

              ws.addCell(new Label(0,0,"Hello World"));

              /pic/p>

              WritableFont wfc = new WritableFont(WritableFont.ARIAL,15,WritableFont.BOLD,true);

              WritableCellFormat wcff= new WritableCellFormat(wfc);

              Label labelcf = new Label(1,0,"Format text",wcff);

              ws.addCell(labelcf);

              /pic/p>

              Number labelN = new Number(0,1,12345);

              ws.addCell(labelN);

              wwb.write();

              wwb.close();

              } catch (Exception ex) {

              Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

              }

              }

              }

              最后給出一段更新表格的代碼:

              /*

              * To change this template, choose Tools | Templates

              * and open the template in the editor.

              */

              package excel;

              import java.io.File;

              import java.io.IOException;

              import java.util.logging.Level;

              import java.util.logging.Logger;

              import jxl.CellType;

              import jxl.Workbook;

              import jxl.read.biff.BiffException;

              import jxl.write.Label;

              import jxl.write.WritableCell;

              import jxl.write.WritableSheet;

              import jxl.write.WritableWorkbook;

              /**

              *

              * @author Wei.Liu

              */

              public class Main {

              /**

              * @param args the command line arguments

              */

              public static void main(String[] args) {

              try {

              Workbook rw = Workbook.getWorkbook(new File("d:\\test.xls"));

              WritableWorkbook wwb = Workbook.createWorkbook(new File("d:\\test.xls"),rw);

              /pic/p>

              WritableSheet ws = wwb.getSheet(0);

              WritableCell wc = ws.getWritableCell(0,0);

              if(wc.getType() == CellType.LABEL){

              Label l= (Label)wc;

              l.setString("Modified!!!");

              }

              wwb.write();

              wwb.close();

              rw.close();

              } catch (Exception ex) {

              Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

              }

              }

              }

            【Java中操作Excel表格方法】相關文章:

            Excel表格的基本操作03-01

            java中BigDecimal的操作方法詳解02-14

            excel表格的基本操作方法之函數應用11-21

            excel表格中除法公式的使用 方法08-20

            Excel表格的基本操作技巧03-19

            excel表格的基本操作教程11-14

            Java數組操作的方法02-20

            java中的JSON操作09-13

            excel表格制作的方法08-30

                    <pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

                    <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

                    <p id="bbfd9"></p>

                    <p id="bbfd9"><cite id="bbfd9"></cite></p>

                      <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

                      <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
                      <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>
                      飘沙影院