JExcelAPI读写excel文件的例子

 JExcelAPI读写excel文件的例子。
import java.io.*;
import jxl.*;
import jxl.write.*;
import jxl.format.*;
import java.util.*;
import java.awt.Color;

public class TestExcel {
 public static void writeExcel(File f) throws Exception {
  jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(f);
  jxl.write.WritableSheet ws = wwb.createSheet("TestSheet1", 0);
  jxl.write.Label labelC = new jxl.write.Label(0, 0, "我爱中国");
  ws.addCell(labelC);
  jxl.write.WritableFont wfc = new jxl.write.WritableFont(
    WritableFont.ARIAL, 20, WritableFont.BOLD, false,
    UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.GREEN);
  jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat(
    wfc);
  wcfFC.setBackground(jxl.format.Colour.RED);
  labelC = new jxl.write.Label(6, 0, "中国爱我a", wcfFC);
  ws.addCell(labelC);
  // 写入Exel工作表
  wwb.write();
  // 关闭Excel工作薄对象
  wwb.close();
 }
 public static void readExcel(File os) throws Exception {
  Workbook wb = Workbook.getWorkbook(os);
  Sheet s = wb.getSheet("Sheet1");
  Cell c = s.getCell(0,0);
  System.out.println(c.getContents());
 }
public static void main(String[] args) throws Exception {
  File f = new File("c:\\kk1.xls");
//  f.createNewFile();
//  writeExcel(f);
  readExcel(f);
 }
} 

你可能感兴趣的:(C++,c,Excel,OS,F#)