Java poi execl export and javapoiexecl Export
First, paste the exported execl:
The front-end interface is as follows:
When you click Export, add the exportDate () function for the onclick event of its button:
function exportDate(){ var begin_Date=$('#dateid').datebox('getValue'); document.getElementById("exportForm").action="../mobileManage/export.do?begin_Date="+begin_Date; document.getElementById("exportForm").submit(); }
The code for export. do in the background is as follows:
@ RequestMapping ("export. do ") public void exportExecl (HttpServletRequest request, HttpServletResponse response) {String beginDate = request. getParameter ("dateid") + "-01"; int maxDay = getCurrMonthDays (beginDate); List <MobileManage> list = getDataList (beginDate); String title = beginDate. substring (0, 4) + "year" + beginDate. subSequence (5, 7) + "month" + "employee work details table"; String [] headers1 = new String [33]; // Date of the table header 1 array, 3. .. String [] headers2 = new String [31]; // header 2 array week, one, two, three... headers1 [0] = "type"; headers1 [1] = "name"; for (int I = 1; I <= maxDay; I ++) {String date = beginDate. substring (0, 8) + (I <10? "0" + I: I + ""); String week = getWeek (date); headers1 [I + 1] = I + ""; headers2 [I-1] = week ;} HSSFWorkbook workbook = new HSSFWorkbook (); // generate a workbook HSSFSheet sheet = workbook. createSheet (title); // create a table HSSFCellStyle = workbook. createCellStyle (); // create a center style. setAlignment (HSSFCellStyle. ALIGN_CENTER); // horizontal style. setverticalignment (HSSFCellStyle. VERTICAL_CENTER); // vertical sheet. setdefacolumcolumnwidth (5 );// Sets the default column width sheet. setColumnWidth (0, 10*256); // you can specify the width of the first and second columns. setColumnWidth (1, 10*256); sheet. setDefaultRowHeight (short) 300); // you can specify HSSFRow row = sheet. createRow (0); // create a table header. addMergedRegion (new CellRangeAddress (0, 1, 0, 0); // sets cross-row sheet. addMergedRegion (new CellRangeAddress (0, 1, 1, 1); HSSFRow rowWeek = sheet. createRow (1); // create table header two HSSFCell cell = null; // fill the table header with data for (int I = 0; I
I have seen many people on the internet saying that short should be added for configuration purposes, but it is no problem for me to write it in Firefox Google for export, of course, there may be problems with different browsers. If so, let's talk about it later.