import java.io.File;
import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Colour;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class JXL001 {
public static void main(String[] args) throws Exception {
// 创建Excel操作
WritableWorkbook workbook = Workbook.createWorkbook(new File("d:/test.xls"));//根据指定的路径创建workbook
WritableSheet sheet = workbook.createSheet("first page", 0);// 创建sheet
// 创建Font
WritableFont myFont = new WritableFont(WritableFont.TIMES,16,WritableFont.BOLD);// 参数对应:字体times,字号16,粗体显示
// 创建cellFormat
WritableCellFormat cellFormat = new WritableCellFormat(myFont);
cellFormat.setBackground(Colour.RED);// 设置背景色
cellFormat.setAlignment(Alignment.CENTRE);// 设置居中
// 创建两个cell
Label label = new Label(0,0,"成功",cellFormat);// 第一列第一行
Number number = new Number(1,0,123.25);// 第二列第一行 ,注:jxl.write.Number
number.setCellFormat(cellFormat);// 设置显示格式
// 向sheet中添加两个cell
sheet.addCell(label);
sheet.addCell(number);
workbook.write();// 写入操作
workbook.close();// 关闭操作
}
}
import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Colour;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class JXL001 {
public static void main(String[] args) throws Exception {
// 创建Excel操作
WritableWorkbook workbook = Workbook.createWorkbook(new File("d:/test.xls"));//根据指定的路径创建workbook
WritableSheet sheet = workbook.createSheet("first page", 0);// 创建sheet
// 创建Font
WritableFont myFont = new WritableFont(WritableFont.TIMES,16,WritableFont.BOLD);// 参数对应:字体times,字号16,粗体显示
// 创建cellFormat
WritableCellFormat cellFormat = new WritableCellFormat(myFont);
cellFormat.setBackground(Colour.RED);// 设置背景色
cellFormat.setAlignment(Alignment.CENTRE);// 设置居中
// 创建两个cell
Label label = new Label(0,0,"成功",cellFormat);// 第一列第一行
Number number = new Number(1,0,123.25);// 第二列第一行 ,注:jxl.write.Number
number.setCellFormat(cellFormat);// 设置显示格式
// 向sheet中添加两个cell
sheet.addCell(label);
sheet.addCell(number);
workbook.write();// 写入操作
workbook.close();// 关闭操作
}
}