1. HSSFSheet sheet = workbook.createSheet("sheetName");    //创建sheet
  2. sheet.setVerticallyCenter(true);
  3. //下面样式可作为导出左右分栏的表格模板
  4. sheet.setColumnWidth((short) 0, (short) 2600);// 设置列宽
  5. sheet.setColumnWidth((short) 1, (short) 2400);
  6. sheet.setColumnWidth((short) 2, (short) 2300);
  7. sheet.setColumnWidth((short) 3, (short) 1600);
  8. sheet.setColumnWidth((short) 4, (short) 1800);
  9. sheet.setColumnWidth((short) 5, (short) 1000);// 空列设置小一些
  10. sheet.setColumnWidth((short) 6, (short) 2600);// 设置列宽
  11. sheet.setColumnWidth((short) 7, (short) 2400);
  12. sheet.setColumnWidth((short) 8, (short) 2300);
  13. sheet.setColumnWidth((short) 9, (short) 1600);
  14. sheet.setColumnWidth((short) 10, (short) 1800);
  15. HSSFCellStyle cellstyle = (HSSFCellStyle) workbook.createCellStyle();// 设置表头样式
  16. cellstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 设置居中
  17. HSSFCellStyle headerStyle = (HSSFCellStyle) workbook .createCellStyle();// 创建标题样式
  18. headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);    //设置垂直居中
  19. headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);   //设置水平居中
  20. HSSFFont headerFont = (HSSFFont) workbook.createFont(); //创建字体样式
  21. headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 字体加粗
  22. headerFont.setFontName("Times New Roman");  //设置字体类型
  23. headerFont.setFontHeightInPoints((short) 8);    //设置字体大小
  24. headerStyle.setFont(headerFont);    //为标题样式设置字体样式
  25. HSSFCellStyle headerStyle1 = (HSSFCellStyle) workbook .createCellStyle();// 创建标题样式1
  26. headerStyle1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
  27. headerStyle1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  28. HSSFFont headerFont1 = (HSSFFont) workbook.createFont();
  29. headerFont1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 字体加粗
  30. headerFont1.setFontName("Times New Roman");
  31. headerFont1.setFontHeightInPoints((short) 8);
  32. headerStyle1.setFont(headerFont1);
  33. HSSFCellStyle headerStyle2 = (HSSFCellStyle) workbook .createCellStyle();// 创建标题样式2
  34. headerStyle2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
  35. headerStyle2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  36. HSSFFont headerFont2 = (HSSFFont) workbook.createFont();
  37. headerFont2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 字体加粗
  38. headerFont2.setFontName("Times New Roman");
  39. headerFont2.setFontHeightInPoints((short) 8);
  40. headerStyle2.setFont(headerFont2);
  41. headerStyle2.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
  42. headerStyle2.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
  43. headerStyle2.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
  44. headerStyle2.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
  45. HSSFCellStyle cell_Style = (HSSFCellStyle) workbook .createCellStyle();// 设置字体样式
  46. cell_Style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  47. cell_Style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直对齐居中
  48. cell_Style.setWrapText(true); // 设置为自动换行
  49. HSSFFont cell_Font = (HSSFFont) workbook.createFont();
  50. cell_Font.setFontName("宋体");
  51. cell_Font.setFontHeightInPoints((short) 8);
  52. cell_Style.setFont(cell_Font);
  53. cell_Style.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
  54. cell_Style.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
  55. cell_Style.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
  56. cell_Style.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
  57. HSSFRow row = sheet.createRow((short)1);    //创建行
  58. HSSFCell cell = row.createCell((short)1);   //创建列
  59. cell.setCellStyle(headerStyle2);    //单元格引用样式

POI-Excel导出样式设置.java67行Java

POI Excel导出样式设置的更多相关文章

  1. Asp.Net中应用Aspose.Cells输出报表到Excel 及样式设置

    解决思路: 1.找个可用的Aspose.Cells(有钱还是买个正版吧,谁开发个东西也不容易): 2.在.Net方案中引用此Cells: 3.写个函数ToExcel(传递一个DataTable),可以 ...

  2. Excel导出时设置单元格的格式为文本

    问题: 用excel导出数据时,如何设置单元格格式的数字分类为"文本",默认是"常规"? 比如:导出编码0235A089,在Excel查看默认显示的是没有前面的 ...

  3. java POI excel 导出复合样式(一个单元格两个字体)

    前言:java poi 导出 excel 时,需要设置一个单元格有多个字体样式,有点类似于富文本. 想要达到的效果(一个单元格里): 我使用的 poi 版本是 <dependency> & ...

  4. poi excel导出,下载

    poi.jar包 public void downExcel(HttpServletResponse response,Page<ShopApply> page) throws Excep ...

  5. POI excel导出

    ******************************* excel表格导出,使用POI实现 ******************************* 实现导出步骤 --配置导出excel ...

  6. poi excel导出 xssf 带下拉框

    需求:导出之后带有二级级联的下拉框.(类似于省市). 最初的思路是怀疑是不是数组内串太多了,导出之后的excel有36行,调试的误区在于刚开始认为对行数有限制,后自己写了一个测试类,才发现不是行数,而 ...

  7. .Net的Excel 导出 格式设置

    添加引用:Microsoft   Excel   11.0   Object   Library ; 添加:using Microsoft.Office.Interop.Excel; 一.打开Exce ...

  8. java poi excel导入模板设置下拉框

    import org.apache.poi.hssf.usermodel.DVConstraint; import org.apache.poi.hssf.usermodel.HSSFCell; im ...

  9. PowerBuilder中调用NPOI进行Excel导出格式设置示例

    // 功能 :新建excel带边框的单元格,格式为数字并显示为美元货币 // 参数 :ai_row,行号:ai_col,列号 // 返回值 :true/false // 作者 :潮崖之飔 // 日期 ...

随机推荐

  1. ios-cocos2d游戏开发基础-CCLayer和Touch事件-开发笔记

    有时候在同一个场景里你需要多个CCLayer.你可以参照以下代码生成这样的场景 +(id) scene { CCScene* scene = [CCScene node]; CCLayer* back ...

  2. Linux likely unlikely

    /************************************************************************* * Linux likely unlikely * ...

  3. LeetCode Letter Combinations of a Phone Number 电话号码组合

    题意:给一个电话号码,要求返回所有在手机上按键的组合,组合必须由键盘上号码的下方的字母组成. 思路:尼玛,一直RE,题意都不说0和1怎么办.DP解决. class Solution { public: ...

  4. 【C#学习笔记】类型转换

    using System; namespace ConsoleApplication { class Program { static void Main(string[] args) { " ...

  5. MyBatis批量删除 多态sql,构建in语句

    <!--==========================删除==================================== -->    <delete id=&quo ...

  6. Android访问权限大全

    android.permission.ACCESS_CHECKIN_PROPERTIES 允许读写访问”properties”表在checkin数据库中,改值可以修改上传( Allows read/w ...

  7. nginx配置:location配置方法及实例详解

    今天深入研究了下nginx的location的用法,已经一些需要注意的细节,现在做一个归纳总结,以备后面查询. location匹配的是nginx的哪个变量? $request_uri locatio ...

  8. XNA Game Studio4.0 Programming 随便读,随便记。

    一.精灵和2D图形 1.什么是2D ? 2D可以理解为 two-Dimentionanl  , 2-dimentional 的缩写. 意就是两维的,比如 数学中的 直角坐标系 所能描述的就是一个2D的 ...

  9. Activity生命周期与状态保存

    弹出系统对话框,程序仍部分可见 onPause 对话框消失时 onResume   调用一个新的Activity,老的Activity不可见时 onPause->onStop 从新的Activi ...

  10. Maven解决Missing artifact com.sun:tools:jar:1.5.0错误

    <dependency> <groupId>com.sun</groupId> <artifactId>tools</artifactId> ...