使用xlsxwriter库就可抄以了。给个例袭子参考下:百# 创建一个新度的excel文件,知demo.xlsxwo" />
乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 如何用python生成excel文件-java excel压缩,java处理excel

如何用python生成excel文件-java excel压缩,java处理excel

作者:乔山办公网日期:

返回目录:excel表格制作




使用xlsxwriter库就可以了。给个例子参考下:

# 创建一个新的excel文件,demo.xlsx

workbook = xlsxwriter.Workbook('demo.xlsx')

worksheet = workbook.add_worksheet()

# 设置A列的宽度

worksheet.set_column('A:A', 20)

bold = workbook.add_format({'bold': True})

worksheet.write('A1', 'Hello')

worksheet.write('A2', 'World', bold)

worksheet.write(2, 0, 123)

worksheet.write(3, 0, 123.456)

worksheet.insert_image('B5', 'logo.png')

workbook.close()

运行结果


网上好多啊 我给你找了一个例子 view plaincopy to clipboardprint?
public static void main(String[] args) {
try {
String filepath = "d:\\问题e79fa5e98193e58685e5aeb9337清单.xls";
FileInputStream fis = new FileInputStream(filepath);
// POIFSFileSystem pfs = new POIFSFileSystem(new FileInputStream("d:\\OA问题清单.xls"));
// HSSFWorkbook hwb = new HSSFWorkbook(pfs);
HSSFWorkbook hwb = new HSSFWorkbook(fis);
// HSSFSheet hws = hwb.getSheetAt(0);
HSSFSheet hws = hwb.getSheet("问题清单");
HSSFRow row = hws.getRow(2);
HSSFCell cell = null;
cell = row.getCell((short) 1);
System.out.println("cellnumber:"+cell.getCellNum());
System.out.println("cellvalue:"+getExcelCellValue(cell));
cell.setCellValue(new Date());
cell = row.getCell((short)2);
HSSFRichTextString rts = new HSSFRichTextString("输入");
cell.setCellValue(rts);
FileOutputStream fos = new FileOutputStream(filepath);
hwb.write(fos);
fis.close();
fos.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(poi.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(poi.class.getName()).log(Level.SEVERE, null, ex);
}

}

public static String getExcelCellValue(HSSFCell cell) {
String ret = "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DecimalFormat df = new DecimalFormat("#");
int celltype = cell.getCellType();
switch(celltype){
case HSSFCell.CELL_TYPE_NUMERIC:
if(HSSFDateUtil.isCellDateFormatted(cell)){
ret = sdf.format(cell.getDateCellValue());
}else{
ret = df.format(cell.getNumericCellValue());
}
break;
case HSSFCell.CELL_TYPE_STRING:
ret = cell.getRichStringCellValue().toString();
break;
default:

}
return ret;
}

看出错信息,需要XSSF处理,是你读取的文件格式不对吧,获取的file是XML文件吗?可以加一句System.out.pringtln(file.getName())看看,poi是处理excel的。

相关阅读

  • 求:<em>JavaWEB</em>实现<em>Excel</em>,W

  • 乔山办公网excel表格制作
  • 可以将word先转为pdf,然后在页面中嵌一个iframe,在这个frame中直接打开这个pdf文件。仅供参考excel的在线预览功能,跪求代码" src="/uploads/tu/144.jpg" style="width: 400px; height: 267px;" />邮箱多少
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网