⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modeltoexcelimpl.java

📁 J2EE项目开发Excel数据导入导出操作组件源代码(附带说明文档)
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            wbook.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (RowsExceededException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (WriteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (BiffException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return excelFile;
    }

    private String[][] getDynamicTitle() {
        int intColumn = excelConfig.getColumnMap().size();
        String[][] propertyName = new String[2][this.dynamicTitleMap.size()];

        int j = -1;
        for (int i = 0; i < intColumn; i++) {
            RuturnPropertyParam propertyBean = (RuturnPropertyParam) excelConfig.getColumnMap().get(String.valueOf(i + 1));
            String name = propertyBean.getName().trim();
            String columnWidth = propertyBean.getColumnWidth();
            if (this.dynamicTitleMap.containsKey(name)) {
                j++;
                propertyName[0][j] = name;
                propertyName[1][j] = columnWidth;

            }
        }

        // 这里可以判断j的值,来判断动态传入的map属性设置是否正确,
        if (j != this.dynamicTitleMap.size()) {
            System.out.println("----动态表头属性值未在配制文件中配制!---");
        }
        return propertyName;
    }

    public void setHeaderCellFormat(WritableCellFormat headerFormat) {
        // TODO Auto-generated method stub
        this.headerFormat = headerFormat;
    }

    public void setNormolCellFormat(WritableCellFormat normolFormat) {
        // TODO Auto-generated method stub
        this.normolFormat = normolFormat;
    }

    public void setRowHeight(int intHeight) {
        // TODO Auto-generated method stub
        this.intHeight = intHeight;
    }

    public void setTitleCellFormat(WritableCellFormat titleFormat) {
        // TODO Auto-generated method stub
        this.titleFormat = titleFormat;
    }

    public void setHeader(String header) {
        // TODO Auto-generated method stub
        this.header = header;
    }

    public String getHeader() {
        return header;
    }

    public WritableCellFormat getHeaderFormat() {
        return headerFormat;
    }

    public int getIntHeight() {
        return intHeight;
    }

    public WritableCellFormat getNormolFormat() {
        return normolFormat;
    }

    public WritableCellFormat getTitleFormat() {
        return titleFormat;
    }

    private WritableCellFormat getDefaultHeaderFormat() {
        WritableFont font = new WritableFont(WritableFont.TIMES, 24, WritableFont.BOLD);// 定义字体
        try {
            font.setColour(Colour.BLUE);// 蓝色字体
        } catch (WriteException e1) {
            // TODO 自动生成 catch 块
            e1.printStackTrace();
        }
        WritableCellFormat format = new WritableCellFormat(font);
        try {
            format.setAlignment(jxl.format.Alignment.CENTRE);// 左右居中
            format.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 上下居中
            format.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);// 黑色边框
            // format.setBackground(Colour.YELLOW);// 黄色背景
            format.setBackground(Colour.GRAY_50);

        } catch (WriteException e) {
            // TODO 自动生成 catch 块
            e.printStackTrace();
        }
        return format;
    }

    private WritableCellFormat getDefaultTitleFormat() {
        // 字体:TIMES,大小为14号,粗体,斜体,有下划线
        WritableFont font = new WritableFont(WritableFont.TIMES, 14, WritableFont.BOLD, true, UnderlineStyle.SINGLE);
        try {
            font.setColour(Colour.BLUE);// 蓝色字体
        } catch (WriteException e1) {
            // TODO 自动生成 catch 块
            e1.printStackTrace();
        }
        WritableCellFormat format = new WritableCellFormat(font);

        try {
            format.setAlignment(jxl.format.Alignment.CENTRE);
            format.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
            format.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
        } catch (WriteException e) {
            // TODO 自动生成 catch 块
            e.printStackTrace();
        }
        return format;
    }

    private WritableCellFormat getDefaultNormolFormat() {
        WritableFont font = new WritableFont(WritableFont.TIMES, 12);
        WritableCellFormat format = new WritableCellFormat(font);
        try {
            format.setAlignment(jxl.format.Alignment.CENTRE);
            format.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
            format.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
        } catch (WriteException e) {
            // TODO 自动生成 catch 块
            e.printStackTrace();
        }
        return format;
    }

    private void copyFile(String src,String dest) throws IOException{
        FileInputStream in=new FileInputStream(src);
        File file=new File(dest);
        if(!file.exists())
            file.createNewFile();
        FileOutputStream out=new FileOutputStream(file);
        int c;        
        byte buffer[]=new byte[1024];
        while((c=in.read(buffer))!=-1){
            for(int i=0;i<c;i++)
                out.write(buffer[i]);        
        }
        in.close();
        out.close();
    }
    private String getParamValue(String strTemp){
        String str = strTemp;
        Object[] keyarr = this.paramMap.keySet().toArray();
        for(int i=0;i<keyarr.length;i++){
            String strkey = "#" + keyarr[i].toString() + "#";
            str = StringUtils.replace(str, strkey, paramMap.get(keyarr[i]).toString());
        }
        return str;
    }
    public Map getDynamicTitleMap() {
        return dynamicTitleMap;
    }

    public void setDynamicTitleMap(Map dynamicTitleMap) {
        this.dynamicTitleMap = dynamicTitleMap;
    }

    public boolean isDynamicTitle() {
        return isDynamicTitle;
    }

    public void setDynamicTitle(boolean isDynamicTitle) {
        this.isDynamicTitle = isDynamicTitle;
    }

    public void setTemplateParam(String templateFile, int startRow, Map paramMap){        
        this.setTemplateParam(true, templateFile, startRow, paramMap);
    }
    public void setTemplateParam(boolean isTemplate,String templateFile,int startRow,Map paramMap){
        this.setTemplateParam(isTemplate, templateFile, startRow, 0, paramMap, true);
    }
    //edit YJM 2008-03-29
    public void setTemplateParam(String templateFile,int startRow,int startColumn,Map paramMap,boolean isInsertRow){
        this.setTemplateParam(true, templateFile, startRow, startColumn, paramMap, isInsertRow);
    }
    public void setTemplateParam(boolean isTemplate,String templateFile,int startRow,int startColumn,Map paramMap,boolean isInsertRow){
        this.isTemplate = isTemplate;
        this.templateFile = templateFile;
        this.startRow = startRow;
        this.paramMap = paramMap;
        this.startColumn = startColumn;
        this.isInsertRow = isInsertRow;
    }
    
    public Map getParamMap() {
        return paramMap;
    }

    public void setParamMap(Map paramMap) {
        this.paramMap = paramMap;
    }

    public int getStartRow() {
        return startRow;
    }

    public void setStartRow(int startRow) {
        this.startRow = startRow;
    }

    public String getTemplateFile() {
        return templateFile;
    }

    public void setTemplateFile(String templateFile) {
        this.templateFile = templateFile;
    }

    public boolean isTemplate() {
        return isTemplate;
    }

    public void setTemplate(boolean isTemplate) {
        this.isTemplate = isTemplate;
    }
    public void setSheet(int sheetNum, String sheetName) {
        // TODO Auto-generated method stub
        this.sheetName=sheetName;
        this.sheetNum=sheetNum;
    }
    public static void main(String[] args) {
        List modelList = new ArrayList();
        for (int i = 0; i < 65; i++) {
            DeptModel dept = new DeptModel();
            dept.setDeptName("总部");
            dept.setDeptCode("A10" + i);
            dept.setDeptNo(i);
            dept.setSendFileName("交南发");
            modelList.add(dept);
        }
        // Colour[] color = Colour.getAllColours();
        // for(int i=0;i<color.length;i++){
        // System.out.println(color[i].getDescription() + " = " +
        // color[i].getDefaultRGB().getRed() + " "
        // +color[i].getDefaultRGB().getGreen() +" " +
        // color[i].getDefaultRGB().getBlue());
        // }
        Map map = new HashMap();
        map.put("deptName", "部门名称1");
        map.put("deptCode", "部门编号1");
        map.put("deptNo", "排序1");

        ExcelConfigManager configManager = ExcelConfigFactory.createExcelConfigManger();
        File excelfile = new File("E:\\workspace\\modeltoexcel.xls");
        ModelToExcelImpl mte = new ModelToExcelImpl(excelfile, configManager.getModel("deptModel", ""), modelList);
        mte.setHeader("部门发文简称(2007)");
        mte.setRowHeight(500);
        mte.setDynamicTitle(true);
        mte.setDynamicTitleMap(map);
        mte.getExcelfile();

    }



    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -