• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

Java 生成的excel为什么是空的呢?

package xiugai;import java.awt.image.BufferedImage;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.imageio.ImageIO;import org.apache.poi.hssf.model.InternalWorkbook;import org.apache.poi.hssf.usermodel.HSSFClientAnchor;import org.apache.poi.hssf.usermodel.HSSFPatriarch;import org.apache.poi.hssf.usermodel.HSSFRow;import org.apache.poi.hssf.usermodel.HSSFSheet;import org.apache.poi.hssf.usermodel.HSSFWorkbook;import org.apache.poi.ss.usermodel.RichTextString;import org.apache.poi.xssf.usermodel.XSSFRow;import org.apache.poi.xssf.usermodel.XSSFSheet;import org.apache.poi.xssf.usermodel.XSSFWorkbook;public class XiuGai {        public static void XiuGai(String filepath) throws Exception {                File file = new File(filepath);                String[] filelist = file.list();                for (int i = 0; i < filelist.length; i++) {                        File readfile = new File(filepath + "\\" + filelist);                        try {                                if (!file.isDirectory()) {                                } else if (file.isDirectory()) {                                        if (!readfile.isDirectory()) {                                                // System.out.println("2name=" + readfile.getName());                                                System.out.println("3name=" + readfile.getName());                                                String name = readfile.getName();                                                System.out.println(name);                                                InputStream is = new FileInputStream(                                                                "C:/Users/adnr/Desktop/哈密公路管理局03版excel/桥梁/小桥/巴里坤公路管理分局/巴里坤公路管理分局小桥excel/"                                                                                + name);                                                // C:\Users\adnr\Desktop\哈密公路管理局03版excel\桥梁\小桥\巴里坤公路管理分局\巴里坤公路管理分局小桥excel                                                HSSFWorkbook demoWorkbook1 = new HSSFWorkbook(is);                                                HSSFSheet sheet = demoWorkbook1.getSheetAt(0);                                                // XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);                                                // XSSFSheet sheet = xssfWorkbook.getSheetAt(0);                                                String XXX = "";                                                String code = readfile.getName().substring(0, readfile.getName().lastIndexOf("."));// 桥梁编码                                                System.out.println(code);                                                String orgname = sheet.getRow(19).getCell(4).getStringCellValue();// 养护单位                                                String bridgeName = sheet.getRow(2).getCell(1).getStringCellValue();                                                String routeName = sheet.getRow(13).getCell(4).getStringCellValue();                                                String routeCode = sheet.getRow(13).getCell(10).getStringCellValue();                                                String type = sheet.getRow(16).getCell(4).getStringCellValue();                                                String pot = sheet.getRow(16).getCell(10).getStringCellValue();                                                String yht = sheet.getRow(19).getCell(10).getStringCellValue();                                                String gl = sheet.getRow(22).getCell(4).getStringCellValue();                                                String glt = sheet.getRow(22).getCell(10).getStringCellValue();                                                String jg = sheet.getRow(25).getCell(4).getStringCellValue();                                                String jgt = sheet.getRow(25).getCell(10).getStringCellValue();                                                XXX = code + "!!" + orgname;                                                FileOutputStream out1 = null;                                                if ("巴里坤公路管理分局".equals(orgname)) {                                                        System.out.println(XXX + "这个是正确的格式!");                                                } else {                                                        String x = "巴里坤公路管理分局";                                                        InputStream that = new FileInputStream(                                                                        "C:/Users/adnr/Desktop/哈密公路管理局03版excel/桥梁/小桥/巴里坤公路管理分局/"                                                                                        + name);                                                        HSSFWorkbook demoWorkbook2 = new HSSFWorkbook(that);                                                        HSSFSheet demo = demoWorkbook2.getSheetAt(0);                                                        ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();                                                        demo.getRow(2).getCell(1).setCellValue(bridgeName);                                                        demo.getRow(13).getCell(4).setCellValue(routeName);                                                        demo.getRow(13).getCell(10).setCellValue(routeCode);                                                        demo.getRow(16).getCell(4).setCellValue(type);                                                        demo.getRow(16).getCell(10).setCellValue(pot);                                                        demo.getRow(19).getCell(4).setCellValue(x);                                                        demo.getRow(19).getCell(10).setCellValue(yht);                                                        demo.getRow(22).getCell(4).setCellValue(gl);                                                        demo.getRow(22).getCell(10).setCellValue(glt);                                                        demo.getRow(25).getCell(4).setCellValue(jg);                                                        demo.getRow(25).getCell(10).setCellValue(jgt);                                                        File imageFile = new File(                                                                        "C:/Users/adnr/Desktop/哈密公路管理局03版数据/桥梁/小桥/巴里坤公路管理分局/巴里坤公路管理分局小桥二维码/" + code + ".png");                                                        BufferedImage bufferImg = ImageIO.read(imageFile);                                                        ImageIO.write(bufferImg, "png", byteArrayOut);                                                        HSSFPatriarch patriarch = demo.createDrawingPatriarch();                                                        HSSFClientAnchor anchor = new HSSFClientAnchor(0, 22, 0, 250,                                                                        (short) 10, 2, (short) 13, 12);// 126, 16                                                        //插入图片                                                        anchor.setAnchorType(3);                                                        patriarch.createPicture(anchor, demoWorkbook2.addPicture(                                                                        byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG));                                                        System.out.println("第" + i + "个表格:" + code                                                                        + "成功移动到伊吾公路管理分局文件夹下");                                                        out1 = new FileOutputStream(                                                                        "C:/Users/adnr/Desktop/哈密公路管理局03版excel/桥梁/小桥/巴里坤公路管理分局/巴里坤公路管理分局小桥excel/1/"                                                                                        + code + ".xls");                                                }                                        } else if (readfile.isDirectory()) {                                                XiuGai(filepath + "\\" + filelist);                                        }                                }                        } catch (FileNotFoundException e) {                                System.out.println("readfile()   Exception:" + e.getMessage());                        }                }        }        public static  void main(String[] args)                        throws Exception {                XiuGai xg = new XiuGai();                try {                        XiuGai("C:/Users/adnr/Desktop/哈密公路管理局03版excel/桥梁/小桥/巴里坤公路管理分局/巴里坤公路管理分局小桥excel/");                        // xg.a();                        // file.getName();                } catch (Exception ex) {                }        }}求大神指点是哪里错了

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!