乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > <em>poi</em> <em>java</em>生成<em&g

<em>poi</em> <em>java</em>生成<em&g

作者:乔山办公网日期:

返回目录:excel表格制作


String filename = "excel名字.xls";
res.setHeader("Content-Type", "application/vnd.ms-excel");
res.setHeader("ContentDisposition", "attachment;filename="
+ new String(filename.getBytes("MS932"), "ISO-8859-1"));
调用一个方法,输出要输出的值,hm是个map
outExcel(hm, res.getOutputStream());
别看下面的方法代码多,其实有用的就几行,主要就是控制e799bee5baa6e78988e69d83363row和cell,设置单元格样式,赋值。

private void outExcel(Map hm, ServletOutputStream out) throws IOException, Exception {
String excelPath = excel模板路径;
excelPath = new String(excelPath.getBytes("iso-8859-1"), "utf-8");
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(excelPath));
HSSFWorkbook wb = new HSSFWorkbook(fs);

HSSFSheet sheet1 = wb.getSheetAt(0);
wb.setSheetName(0, "SheetName");
HSSFPrintSetup ps1 = sheet1.getPrintSetup();
ps1.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);

HSSFRow row = sheet1.getRow((short) (1));
HSSFCell cell = row.getCell((short) (1));
String dataNumber = (String) hm.get("dataNumber");
cell.setCellValue(new HSSFRichTextString(dataNumber));
String birthAddress = (String) hm.get("birthAddress");
cell = row.getCell((short) (5));
cell.setCellValue(new HSSFRichTextString(birthAddress));
String acceptDate = (String) hm.get("acceptDate");
row = sheet1.getRow((short) (2));
cell = row.getCell((short) (1));
cell.setCellValue(new HSSFRichTextString(acceptDate));
String usedistrictCode = (String) hm.get("usedistrictCode");
cell = row.getCell((short) (5));
cell.setCellValue(new HSSFRichTextString(usedistrictCode));
String allegationZipCode = (String) hm.get("allegationZipCode");
row = sheet1.getRow((short) (3));
cell = row.getCell((short) (1));
cell.setCellValue(new HSSFRichTextString(allegationZipCode));
String birthName = (String) hm.get("birthName");
cell = row.getCell((short) (5));
cell.setCellValue(new HSSFRichTextString(birthName));
String allegationAddress = (String) hm.get("allegationAddress");
row = sheet1.getRow((short) (4));
cell = row.getCell((short) (1));
cell.setCellValue(new HSSFRichTextString(allegationAddress));
String birthTellNumber = (String) hm.get("birthTellNumber");
cell = row.getCell((short) (5));
cell.setCellValue(new HSSFRichTextString(birthTellNumber));
String allegationName = (String) hm.get("allegationName");
row = sheet1.getRow((short) (5));
cell = row.getCell((short) (1));
cell.setCellValue(new HSSFRichTextString(allegationName));
// 敪惗尮娆庬僐乕僪
String industrialCode = (String) hm.get("industrialCode");
cell = row.getCell((short) (5));
cell.setCellValue(new HSSFRichTextString(industrialCode));
// 怽棫幰背榖斣崋
String allegationTellNumber = (String) hm.get("allegationTellNumber");
row = sheet1.getRow((short) (6));
cell = row.getCell((short) (1));
cell.setCellValue(new HSSFRichTextString(allegationTellNumber));
// 敪惗尮巤愝摍
String birthFacilitiesetc = (String) hm.get("birthFacilitiesetc");
cell = row.getCell((short) (5));
cell.setCellValue(new HSSFRichTextString(birthFacilitiesetc));
// 怽棫撪梕
String allegation = (String) hm.get("allegation");
row = sheet1.getRow((short) (7));
cell = row.getCell((short) (1));
cell.setCellValue(new HSSFRichTextString(allegation));
// 挷嵏巜摫撪梕
String guidance = (String) hm.get("guidance");
row = sheet1.getRow((short) (8));
cell = row.getCell((short) (1));
cell.setCellValue(new HSSFRichTextString(guidance));
// 应掕擭宁担1
String sokuDate1 = (String) hm.get("sokuDate1");
row = sheet1.getRow((short) (9));
cell = row.getCell((short) (2));
cell.setCellValue(new HSSFRichTextString(sokuDate1));
// 应掕擭宁担2
String sokuDate2 = (String) hm.get("sokuDate2");
cell = row.getCell((short) (3));
cell.setCellValue(new HSSFRichTextString(sokuDate2));
// 应掕擭宁担3
String sokuDate3 = (String) hm.get("sokuDate3");
cell = row.getCell((short) (4));
cell.setCellValue(new HSSFRichTextString(sokuDate3));
// 应掕擭宁担4
String sokuDate4 = (String) hm.get("sokuDate4");
cell = row.getCell((short) (5));
cell.setCellValue(new HSSFRichTextString(sokuDate4));
// 应掕擭宁担5
String sokuDate5 = (String) hm.get("sokuDate5");
cell = row.getCell((short) (6));
cell.setCellValue(new HSSFRichTextString(sokuDate5));
// 应掕擭宁担6
String sokuDate6 = (String) hm.get("sokuDate6");
cell = row.getCell((short) (7));
cell.setCellValue(new HSSFRichTextString(sokuDate6));
// 应掕帪岗1
String sokuTime1 = (String) hm.get("sokuTime1");
row = sheet1.getRow((short) (10));
cell = row.getCell((short) (2));
cell.setCellValue(new HSSFRichTextString(sokuTime1));
// 应掕帪岗2
String sokuTime2 = (String) hm.get("sokuTime2");
cell = row.getCell((short) (3));
cell.setCellValue(new HSSFRichTextString(sokuTime2));
// 应掕帪岗3
String sokuTime3 = (String) hm.get("sokuTime3");
cell = row.getCell((short) (4));
cell.setCellValue(new HSSFRichTextString(sokuTime3));
// 应掕帪岗4
String sokuTime4 = (String) hm.get("sokuTime4");
cell = row.getCell((short) (5));
cell.setCellValue(new HSSFRichTextString(sokuTime4));
// 应掕帪岗5
String sokuTime5 = (String) hm.get("sokuTime5");
cell = row.getCell((short) (6));
cell.setCellValue(new HSSFRichTextString(sokuTime5));
// 应掕帪岗6
String sokuTime6 = (String) hm.get("sokuTime6");
cell = row.getCell((short) (7));
cell.setCellValue(new HSSFRichTextString(sokuTime6));
// 帋桠斣崋1
String shiryoNumber1 = (String) hm.get("shiryoNumber1");
row = sheet1.getRow((short) (11));
cell = row.getCell((short) (2));
cell.setCellValue(new HSSFRichTextString(shiryoNumber1));
// 帋桠斣崋2
String shiryoNumber2 = (String) hm.get("shiryoNumber2");
cell = row.getCell((short) (3));
cell.setCellValue(new HSSFRichTextString(shiryoNumber2));
// 帋桠斣崋3
String shiryoNumber3 = (String) hm.get("shiryoNumber3");
cell = row.getCell((short) (4));
cell.setCellValue(new HSSFRichTextString(shiryoNumber3));
// 帋桠斣崋4
String shiryoNumber4 = (String) hm.get("shiryoNumber4");
cell = row.getCell((short) (5));
cell.setCellValue(new HSSFRichTextString(shiryoNumber4));
// 帋桠斣崋5
String shiryoNumber5 = (String) hm.get("shiryoNumber5");
cell = row.getCell((short) (6));
cell.setCellValue(new HSSFRichTextString(shiryoNumber5));
// 帋桠斣崋6
String shiryoNumber6 = (String) hm.get("shiryoNumber6");
cell = row.getCell((short) (7));
cell.setCellValue(new HSSFRichTextString(shiryoNumber6));
// 婥壏1
String temp1 = (String) hm.get("temp1");
row = sheet1.getRow((short) (12));
cell = row.getCell((short) (2));
cell.setCellValue(new HSSFRichTextString(temp1));
// 婥壏2
String temp2 = (String) hm.get("temp2");
cell = row.getCell((short) (3));
cell.setCellValue(new HSSFRichTextString(temp2));
// 婥壏3
String temp3 = (String) hm.get("temp3");
cell = row.getCell((short) (4));
cell.setCellValue(new HSSFRichTextString(temp3));
// 婥壏4
String temp4 = (String) hm.get("temp4");
cell = row.getCell((short) (5));
cell.setCellValue(new HSSFRichTextString(temp4));
// 婥壏5
String temp5 = (String) hm.get("temp5");
cell = row.getCell((short) (6));
cell.setCellValue(new HSSFRichTextString(temp5));
// 婥壏6
String temp6 = (String) hm.get("temp6");
cell = row.getCell((short) (7));
cell.setCellValue(new HSSFRichTextString(temp6));
// 幖搙1
String humid1 = (String) hm.get("humid1");
row = sheet1.getRow((short) (13));
cell = row.getCell((short) (2));
cell.setCellValue(new HSSFRichTextString(humid1));
// 幖搙2
String humid2 = (String) hm.get("humid2");
cell = row.getCell((short) (3));
cell.setCellValue(new HSSFRichTextString(humid2));
// 幖搙3
String humid3 = (String) hm.get("humid3");
cell = row.getCell((short) (4));
cell.setCellValue(new HSSFRichTextString(humid3));
// 幖搙4
String humid4 = (String) hm.get("humid4");
cell = row.getCell((short) (5));
cell.setCellValue(new HSSFRichTextString(humid4));
// 幖搙5
String humid5 = (String) hm.get("humid5");
cell = row.getCell((short) (6));
cell.setCellValue(new HSSFRichTextString(humid5));
// 幖搙6
String humid6 = (String) hm.get("humid6");
cell = row.getCell((short) (7));
cell.setCellValue(new HSSFRichTextString(humid6));
// 晽岦1
String windCode1 = (String) hm.get("windCode1");
row = sheet1.getRow((short) (14));
cell = row.getCell((short) (2));
cell.setCellValue(new HSSFRichTextString(windCode1));
// 晽岦2
String windCode2 = (String) hm.get("windCode2");
cell = row.getCell((short) (3));
cell.setCellValue(new HSSFRichTextString(windCode2));
String windCode3 = (String) hm.get("windCode3");
cell = row.getCell((short) (4));
cell.setCellValue(new HSSFRichTextString(windCode3));
String windCode4 = (String) hm.get("windCode4");
cell = row.getCell((short) (5));
cell.setCellValue(new HSSFRichTextString(windCode4));
String windCode5 = (String) hm.get("windCode5");
cell = row.getCell((short) (6));
cell.setCellValue(new HSSFRichTextString(windCode5));
String windCode6 = (String) hm.get("windCode6");
cell = row.getCell((short) (7));
cell.setCellValue(new HSSFRichTextString(windCode6));
String windSpeed1 = (String) hm.get("windSpeed1");
row = sheet1.getRow((short) (15));
cell = row.getCell((short) (2));
cell.setCellValue(new HSSFRichTextString(windSpeed1));
String windSpeed2 = (String) hm.get("windSpeed2");
cell = row.getCell((short) (3));
cell.setCellValue(new HSSFRichTextString(windSpeed2));
String windSpeed3 = (String) hm.get("windSpeed3");
cell = row.getCell((short) (4));
cell.setCellValue(new HSSFRichTextString(windSpeed3));
String windSpeed4 = (String) hm.get("windSpeed4");
cell = row.getCell((short) (5));
cell.setCellValue(new HSSFRichTextString(windSpeed4));
String windSpeed5 = (String) hm.get("windSpeed5");
cell = row.getCell((short) (6));
cell.setCellValue(new HSSFRichTextString(windSpeed5));
String windSpeed6 = (String) hm.get("windSpeed6");
cell = row.getCell((short) (7));
cell.setCellValue(new HSSFRichTextString(windSpeed6));
String pick1 = (String) hm.get("pick1");
row = sheet1.getRow((short) (16));
cell = row.getCell((short) (2));
cell.setCellValue(new HSSFRichTextString(pick1));
String pick2 = (String) hm.get("pick2");
cell = row.getCell((short) (3));
cell.setCellValue(new HSSFRichTextString(pick2));
String pick3 = (String) hm.get("pick3");
cell = row.getCell((short) (4));
cell.setCellValue(new HSSFRichTextString(pick3));
String pick4 = (String) hm.get("pick4");
cell = row.getCell((short) (5));
cell.setCellValue(new HSSFRichTextString(pick4));
String pick5 = (String) hm.get("pick5");
cell = row.getCell((short) (6));
cell.setCellValue(new HSSFRichTextString(pick5));
String pick6 = (String) hm.get("pick6");
cell = row.getCell((short) (7));
cell.setCellValue(new HSSFRichTextString(pick6));
String smell1 = (String) hm.get("smell1");
row = sheet1.getRow((short) (17));
cell = row.getCell((short) (2));
cell.setCellValue(new HSSFRichTextString(smell1));
String smell2 = (String) hm.get("smell2");
cell = row.getCell((short) (3));
cell.setCellValue(new HSSFRichTextString(smell2));
String smell3 = (String) hm.get("smell3");
cell = row.getCell((short) (4));
cell.setCellValue(new HSSFRichTextString(smell3));
String smell4 = (String) hm.get("smell4");
cell = row.getCell((short) (5));
cell.setCellValue(new HSSFRichTextString(smell4));
String smell5 = (String) hm.get("smell5");
cell = row.getCell((short) (6));
cell.setCellValue(new HSSFRichTextString(smell5));
String smell6 = (String) hm.get("smell6");
cell = row.getCell((short) (7));
cell.setCellValue(new HSSFRichTextString(smell6));
wb.write(out);
out.close();
}

比如第一行第一列到第4列合并,那么你合并后的编号就还是第一行第一列,就是给第一行第一列赋值就可以了
源码贴出来,我来帮你改。原因应该是你没把 合并后的单元格赋值导致的。看看poi的api文档。

如下:e68a847a686964616f365
public static String do_post(String url, List<NameValuePair> name_value_pair) throws IOException {
        String body = "{}";
        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            HttpPost httpost = new HttpPost(url);
            httpost.setEntity(new UrlEncodedFormEntity(name_value_pair, StandardCharsets.UTF_8));
            HttpResponse response = httpclient.execute(httpost);
            HttpEntity entity = response.getEntity();
            body = EntityUtils.toString(entity);
        } finally {
            httpclient.getConnectionManager().shutdown();
        }
        return body;
    }
    public static String do_get(String url) throws ClientProtocolException, IOException {
        String body = "{}";
        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            HttpGet httpget = new HttpGet(url);
            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            body = EntityUtils.toString(entity);
        } finally {
            httpclient.getConnectionManager().shutdown();
        }
        return body;
    }

相关阅读

  • -java poi excel模板,java使用poi读取excel

  • 乔山办公网excel表格制作
  • 需要导入jxl.jar (在网上可以下载,然后放到lib文件夹中)开放分类: java通过java操作excel表格的工抄具类库支持Excel 95-2000的所有版本生成Excel 2000标准格式支持字体、数字、日期操作 能够
  • <em>Java</em>利用<em>POI导入excel</em>表格

  • 乔山办公网excel表格制作
  • 参考答案   4.如果现在这个时代能出全才,那便是应试教育的幸运和这个时代的不幸。如果有,他便是人中之王,可惜没有,所以我们只好把“全”字人下的“王”给拿掉。时代需要
关键词不能为空
极力推荐

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