标签:des style blog color os io java ar for
1.jxl生成excel
/** * @desc 写入 */ public void writeToExcel() throws Exception{ File file = new File(writePath);//创建文件 //创建工作薄 WritableWorkbook wwk=Workbook.createWorkbook(file);//创建工作薄 WritableSheet sheet=wwk.createSheet(this.excelName, 0);//创建sheet Label title=new Label(0,0,this.title);//定义标题 //创建标题样式 WritableFont wf_title = new WritableFont(WritableFont.ARIAL, 15, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); // 定义格式 字体 下划线 斜体 粗体 颜色 WritableCellFormat wcf_title = new WritableCellFormat(wf_title); // 单元格定义 wcf_title.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式 title.setCellFormat(wcf_title);//设置样式 List<String> columns = getHeadName();//通过查询方法获取标表头集合 if(columns.size()!=0){//合并单元格 sheet.mergeCells(0, 0, columns.size(), 0); } sheet.addCell(title);//写入标题 //设置列样式 WritableFont columnStyle = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); // 定义格式 字体 下划线 斜体 粗体 颜色 WritableCellFormat column = new WritableCellFormat(columnStyle); // 单元格定义 column.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式 //写表头 for(int i=0; i<columns.size();i++){ Label label=new Label(i,1,columns.get(i)); label.setCellFormat(column); sheet.addCell(label); } wwk.write(); wwk.close(); wwk = null; }
2.java swing 保存弹框
JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(null);//设置默认打开路径 chooser.setDialogType(JFileChooser.SAVE_DIALOG);//设置保存对话框 XlsFileFilter xlsFileFilter = new XlsFileFilter();//文件过滤 chooser.addChoosableFileFilter(xlsFileFilter);//设置文件过滤 int index = chooser.showDialog(null, "保存文件");//标题 if (index == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); String fileName = chooser.getName(file) + ".xls"; String path = chooser.getCurrentDirectory().getAbsolutePath() +"\\"+ fileName; try { System.out.println("选择"+path); TableExToExcel te = new TableExToExcel(path,"排班表",lb_tableName.getText(),tableEx); te.writeToExcel(); AloneHelper.showMsg("提示", "保存成功!"); } catch (Exception e) { e.printStackTrace(); } }
标签:des style blog color os io java ar for
原文地址:http://www.cnblogs.com/zhanglu-cape/p/3954267.html