DOM 4 jとPOIに基づいて実現されたXMLファイルをXLS(すなわち標準EXCEL)に変換するJAVAプログラム


DOM 4 jとPOIに基づいて実現されたXMLファイルをXLS(すなわち標準EXCEL)に変換するJAVAプログラム
初めてブログを書くのはちょっと緊張しましたが、大牛さんによろしくお願いします.
大四犬は最近会社に実習に来て、マネージャーは大いに開発能力をテストする任務を与えて、xmlファイルを読んでxlsファイルに変換して、このxmlは接尾辞名を修正することでxlsで開くことができます.したがって、xml形式のファイルを読み取り、その中のデータをxmlのstyle形式でEXCEL標準セル形式に書き換える必要があります.注意:このプログラムには一部の巧みさがあり、一部の共通フォーマットは読み込まれたものではなく、直接設定されています.もしよろしければ、完全なプロジェクトリンクアドレスを取らないでください.https://download.csdn.net/download/amazon_king/10981005
インプリメンテーションプロセス
まずxml形式のファイルを貼り付けます.




	
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	
	
		
	


	
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
			
			
		
		
			
				     
			
		
		
			
				    :
			
			
				2012-09-10
			
			
				    :
			
			
				2012-09-10
			
			
			
				    :
			
			
				    
			
		
		
			
				     : 880004_880004
			
		
		
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				   
			
			
				    
			
		
		
			
				test13
			
			
				880004
			
			
				11111111
			
			
				20120910
			
			
				42-    
			
			
				0
			
			
				985
			
			
				977.12
			
			
				985.00
			
			
				7.88
			
			
				1.0000
			
		
		
			
				test13
			
			
				880004
			
			
				11111111
			
			
				20120910
			
			
				22-  
			
			
				1000
			
			
				0
			
			
				985
			
			
				985.00
			
			
				15.00
			
			
				1.0000
			
		
		
			
				    
			
			
				1000.0
			
			
				985.0
			
			
				1962.12
			
			
				1970.0
			
			
				22.88
			
			
		
		
			
				*                      
			
		
		
			
				**       ,                
			
		
		
			
				***              [email protected]
			
		
		
			
				****                              ,                                     
			
		
		
			
				*****                         ,        !
			
		
		
			
		
		
			
				     
			
		
		
			
				    :
			
			
				2012-09-10
			
			
				    :
			
			
				2012-09-10
			
			
			
				    :
			
			
				    
			
		
		
			
				     : 880005_880005
			
		
		
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				   
			
			
				    
			
		
		
			
				test51
			
			
				880005
			
			
				530101198604280050
			
			
				20120910
			
			
				22-  
			
			
				5000
			
			
				0
			
			
				4950
			
			
				4950.00
			
			
				50.00
			
			
				1.0000
			
		
		
			
				    
			
			
				5000.0
			
			
				0.0
			
			
				4950.0
			
			
				4950.0
			
			
				50.0
			
			
		
		
			
				*                      
			
		
		
			
				**       ,                
			
		
		
			
				***              [email protected]
			
		
		
			
				****                              ,                                     
			
		
		
			
				*****                         ,        !
			
		
		
			
		
		
			
				     
			
		
		
			
				    :
			
			
				2012-09-10
			
			
				    :
			
			
				2012-09-10
			
			
			
				    :
			
			
				    
			
		
		
			
				     : 880006_880006
			
		
		
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				    
			
			
				   
			
			
				    
			
		
		
			
				test31
			
			
				880006
			
			
				111111115
			
			
				20120910
			
			
				24-  
			
			
				0
			
			
				985
			
			
				985
			
			
				985.00
			
			
				0.00
			
			
				1.0000
			
		
		
			
				test31
			
			
				880006
			
			
				111111115
			
			
				20120910
			
			
				24-  
			
			
				0
			
			
				985
			
			
				985
			
			
				985.00
			
			
				0.00
			
			
				1.0000
			
		
		
			
				    
			
			
				0.0
			
			
				1970.0
			
			
				1970.0
			
			
				1970.0
			
			
				0.0
			
			
		
		
			
				*                      
			
		
		
			
				**       ,                
			
		
		
			
				***              [email protected]
			
		
		
			
				****                              ,                                     
			
		
		
			
				*****                         ,        !
			
		
		
			
				   :
			
			
				     
			
			
				 
			
			
				1
			
			
				 / 
			
			
				1
			
			
				 
			
			
				    :
			
			
				2019 2 18    3:43
			
			
				  :
			
			
		
	
9

最初は本当に霧がかかっていて、何の見当もつかなかったが、その後、関連資料を探したり先輩に相談したりして、やっと実現方法を見つけた.
1.まずdom 4 jでxmlファイルを解析する、その中のstyle形式及びtable内の関連データをエンティティークラスに格納エンティティークラスには、Column(格納列情報)、Style(格納フォーマット情報)、Information(格納tableテーブルのデータ情報)の3つが含まれる.次に、Columnクラスのcolumn関連スタイル情報を読み出し、列の幅などのデータを設定します.3.informationクラスのデータを読み込み、Excelに書き込みます.4.次にstyleクラスのスタイル情報を読み出し、POIでフォーマットを書き込む.
次に、関連コード、合計5つのクラス、およびxmlファイル(プログラムがmavenプロジェクトであるため、関連するパッケージ依存性が格納されます)
Styleクラス:
package com.jzcf;


import java.util.List;

public class Style {
    private int id;
    private Alignment alignment;
    private List borders;
    private Font  font;
    private Interior interior;
    private NumberFormat numberFormat;

    public Style() {
    }
    public NumberFormat getNumberFormat() {
        return numberFormat;
    }

    public void setNumberFormat(NumberFormat numberFormat) {
        this.numberFormat = numberFormat;
    }


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Alignment getAlignment() {
        return alignment;
    }

    public void setAlignment(Alignment alignment) {
        this.alignment = alignment;
    }

    public List getBorders() {
        return borders;
    }

    public void setBorders(List borders) {
        this.borders = borders;
    }

    public Font getFont() {
        return font;
    }

    public void setFont(Font font) {
        this.font = font;
    }

    public Interior getInterior() {
        return interior;
    }

    public void setInterior(Interior interior) {
        this.interior = interior;
    }

    public Style(int id, Alignment alignment, List borders, Font font, Interior interior) {
        this.id = id;
        this.alignment = alignment;
        this.borders= borders;
        this.font = font;
        this.interior = interior;
    }

    public Style(int id, NumberFormat numberFormat) {
        this.id = id;
        this.numberFormat = numberFormat;
    }

    public static class Alignment {
        private String horizontal;
        private String vertical;
        private String wrapText;

    public  Alignment(){

    }

        public Alignment(String horizontal, String vertical, String wrapText) {
            this.horizontal = horizontal;
            this.vertical = vertical;
            this.wrapText = wrapText;
        }

        public String getHorizontal() {
            return horizontal;
        }

        public void setHorizontal(String horizontal) {
            this.horizontal = horizontal;
        }

        public String getVertical() {
            return vertical;
        }

        public void setVertical(String vertical) {
            this.vertical = vertical;
        }

        public String getWrapText() {
            return wrapText;
        }

        public void setWrapText(String wrapText) {
            this.wrapText = wrapText;
        }
    }

    public static class Border {
            private String position;
            private String linestyle;
            private int weight;
            private String color;

        public Border() {
        }

        public Border(String position, String linestyle, int weight, String color) {
            this.position = position;
            this.linestyle = linestyle;
            this.weight = weight;
            this.color = color;
        }

        public String getPosition() {
            return position;
        }

        public void setPosition(String position) {
            this.position = position;
        }

        public String getLinestyle() {
            return linestyle;
        }

        public void setLinestyle(String linestyle) {
            this.linestyle = linestyle;
        }

        public int getWeight() {
            return weight;
        }

        public void setWeight(int weight) {
            this.weight = weight;
        }

        public String getColor() {
            return color;
        }

        public void setColor(String color) {
            this.color = color;
        }
    }

    public static class Font {
            private String fontName;
            private double size;
            private int bold;
            private String color;

        public Font() {
        }

        public Font(String fontName, double size, int bold, String color) {
            this.fontName = fontName;
            this.size = size;
            this.bold = bold;
            this.color = color;
        }

        public String getFontName() {
            return fontName;
        }

        public void setFontName(String fontName) {
            this.fontName = fontName;
        }

        public double getSize() {
            return size;
        }

        public void setSize(double size) {
            this.size = size;
        }

        public int getBold() {
            return bold;
        }

        public void setBold(int bold) {
            this.bold = bold;
        }

        public String getColor() {
            return color;
        }

        public void setColor(String color) {
            this.color = color;
        }
    }

    public static class Interior {
        private String color;
        private String pattern;

        public Interior() {
        }

        public Interior(String color, String pattern) {
            this.color = color;
            this.pattern = pattern;
        }

        public String getColor() {
            return color;
        }

        public void setColor(String color) {
            this.color = color;
        }

        public String getPattern() {
            return pattern;
        }

        public void setPattern(String pattern) {
            this.pattern = pattern;
        }
    }

    public static class NumberFormat {
        private String format;

        public NumberFormat() {
        }

        public String getFormat() {
            return format;
        }

        public void setFormat(String format) {
            this.format = format;
        }

        public NumberFormat(String format) {
            this.format = format;
        }
    }
}


Columnクラス:
package com.jzcf;

public class Column {
    private double width;
    private int autofitwidth=0;

    public Column() {
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public Column(double width, int autofitwidth) {
        this.width = width;
        this.autofitwidth = autofitwidth;
    }
}


Informationクラス:
package com.jzcf;

import java.util.List;

public class Information {
    private String name;
   private List row;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Information() {
    }

    public List getRow() {
        return row;
    }

    public void setRow(List row) {
        this.row = row;
    }

    public Information(String name, List row) {
        this.name = name;
        this.row = row;
    }

    public static class Row {
        private int autofitheight;
        private double height;
        private List  cell;

        public Row() {
        }

        public Row(int autofitheight, double height, List cell) {
            this.autofitheight = autofitheight;
            this.height = height;
            this.cell = cell;
        }

        public int getAutofitheight() {
            return autofitheight;
        }

        public void setAutofitheight(int autofitheight) {
            this.autofitheight = autofitheight;
        }

        public double getHeight() {
            return height;
        }

        public void setHeight(double height) {
            this.height = height;
        }

        public List getCell() {
            return cell;
        }

        public void setCell(List cell) {
            this.cell = cell;
        }

        public static class Cell {
            private int index;
            private int styleID;
            private int MergeAcross;
            private int MergeDown;
            private Data data;

            public Cell() {
            }

            public Cell(int index, int styleID, int mergeAcross, int mergeDown, Data data) {
                this.index = index;
                this.styleID = styleID;
                MergeAcross = mergeAcross;
                MergeDown = mergeDown;
                this.data = data;
            }

            public int getIndex() {
                return index;
            }

            public void setIndex(int index) {
                this.index = index;
            }

            public int getStyleID() {
                return styleID;
            }

            public void setStyleID(int styleID) {
                this.styleID = styleID;
            }

            public int getMergeAcross() {
                return MergeAcross;
            }

            public void setMergeAcross(int mergeAcross) {
                MergeAcross = mergeAcross;
            }

            public int getMergeDown() {
                return MergeDown;
            }

            public void setMergeDown(int mergeDown) {
                MergeDown = mergeDown;
            }

            public Data getData() {
                return data;
            }

            public void setData(Data data) {
                this.data = data;
            }

            public static class Data {
                private int ticked;
                private String type;
                private String dat;//        

                public int getTicked() {
                    return ticked;
                }

                public void setTicked(int ticked) {
                    this.ticked = ticked;
                }

                public String getType() {
                    return type;
                }

                public void setType(String type) {
                    this.type = type;
                }

                public String getDat() {
                    return dat;
                }

                public void setDat(String dat) {
                    this.dat = dat;
                }

                public Data() {
                }

                public Data(int ticked, String type, String dat) {
                    this.ticked = ticked;
                    this.type = type;
                    this.dat = dat;
                }
            }
        }
    }
}


XmlReaderクラス(xmlファイルの解析に使用):
package com.jzcf;



import java.util.*;

import org.dom4j.Document;
import org.dom4j.DocumentException;

import org.dom4j.Element;


import java.util.List;

public class XmlReader {
    public static Map  getStyle(Document document) {//    
        Map styleMap = new LinkedHashMap();//    LinkedHashMap    style,  id  
        Style style = null; //    Style         

        Style.NumberFormat numberFormat = new Style.NumberFormat();

        Element root = document.getRootElement();//     
        Element styles = root.element("Styles");//       Styles  
        List lstyle = styles.elements("Style");//  Styles  Style  
        Iterator> it = lstyle.iterator();
        Element e = (Element) it.next();
        while (it.hasNext()) {
            style = new Style();//    Style         
            e = (Element) it.next();
            int id = Integer.parseInt(e.attributeValue("ID"));
            style.setId(id);//  style id
            if (id == 1) {// id 1 ,          
               /* Element enumberFormat = e.element("NumberFormat");//  Style  NumberFormat  
                numberFormat.setFormat(enumberFormat.attributeValue("Format"));
                style.setNumberFormat(numberFormat);*/
                continue;
            }
            Style.Alignment alignment = new Style.Alignment();
            Element ealignment = e.element("Alignment");//  Style  Alignment  
            //  aligment     ,    style aliment  
            alignment.setHorizontal(ealignment.attributeValue("Horizontal"));
            alignment.setVertical(ealignment.attributeValue("Vertical"));
            alignment.setWrapText(ealignment.attributeValue("WrapText"));
            style.setAlignment(alignment);

            Element Borders = e.element("Borders");//  Style  Borders  
            List Border = Borders.elements("Border");//  Borders  Border  
            Iterator> bdIt = Border.iterator();//      Border  
            //  List   borders    border   style

            List lborders = new ArrayList();
            while (bdIt.hasNext()) {
                Element bd = (Element) bdIt.next();
                Style.Border border = new Style.Border();
                border.setPosition(bd.attributeValue("Position"));
                if (bd.attribute("LineStyle") != null) {
                    border.setLinestyle(bd.attributeValue("LineStyle"));
                    int weight = Integer.parseInt(bd.attributeValue("Weight"));
                    border.setWeight(weight);
                    border.setColor(bd.attributeValue("Color"));
                }
                lborders.add(border);
            }
            style.setBorders(lborders);
            for (int i = 0; i < style.getBorders().size(); i++) {
                // System.out.println(style.getBorders().get(i).getPosition());
            }

            //  font     ,    style font  
            Style.Font font = new Style.Font();
            Element efont = e.element("Font");
            font.setFontName(efont.attributeValue("FontName"));
            double size = Double.parseDouble(efont.attributeValue("Size"));
            font.setSize(size);
            if (efont.attribute("Bold") != null) {
                int bold = Integer.parseInt(efont.attributeValue("Bold"));
                font.setBold(bold);
            }
            font.setColor(efont.attributeValue("Color"));
            style.setFont(font);
            //  Interior     ,    style interior  
            Style.Interior interior = new Style.Interior();
            if (e.element("Interior") != null) {
                Element einterior = e.element("Interior");
                interior.setColor(einterior.attributeValue("Color"));
                interior.setPattern(einterior.attributeValue("Pattern"));
            }
            style.setInterior(interior);
            if (e.element("NumberFormat") != null) {
                //  NumberFormat     ,    style NumberFormat  
                Element enumberFormat = e.element("NumberFormat");//  Style  Alignment  
                numberFormat.setFormat(enumberFormat.attributeValue("Format"));
                style.setNumberFormat(numberFormat);
            }
            styleMap.put(id, style);

        }

        Element Names = root.element("Names");//       Names  
        Element NamedRange = Names.element("NamedRange");//       NamedRange  
        String name = NamedRange.attributeValue("Name");//  ss:Name
        String namedRange = NamedRange.attributeValue("RefersTo");//  ss:RefersTo
        return styleMap;
    }
public  static  List  getColumn(Document document){
    Element root = document.getRootElement();
    Element worksheet = root.element("Worksheet");//       Worksheet  
    String name = worksheet.attributeValue("Name");
    Element table = worksheet.element("Table");//  Worksheet  ss:Table  
    List column = table.elements("Column");//  ss:Table    ss:Column  
    List columns = new ArrayList();
    for (Iterator> it = column.iterator(); it.hasNext(); ) {
        Column column1 = new Column();//    column   column   
        Element eColumn = (Element) it.next();
        double width = Double.parseDouble(eColumn.attributeValue("Width"));
        column1.setWidth(width);
        columns.add(column1);
    }
   return columns;
}
    public static Information getData(Document document) {//      
        Element root = document.getRootElement();
        Element worksheet = root.element("Worksheet");//       Worksheet  
        Element table = worksheet.element("Table");//  Worksheet  ss:Table  

        Information information = new Information();
        information.setName(worksheet.attributeValue("Name"));
        List row = table.elements("Row");//  Worksheet  Row  
        List lrow = new ArrayList();
        for (Iterator> it = row.iterator(); it.hasNext(); ) {
            //  row        list,  information
            Information.Row row1 = new Information.Row();
            Element eRow = (Element) it.next();
            int autofitheight = Integer.parseInt(eRow.attributeValue("AutoFitHeight"));
            row1.setAutofitheight(autofitheight);
            if (eRow.attributeValue("Height")!= null) {
                double height = Double.parseDouble(eRow.attributeValue("Height"));
                row1.setHeight(height);
            }
            lrow.add(row1);//    row     list lrow 
            List lcell = new ArrayList();//list    cell
            List cell = eRow.elements("Cell");//  Row  Cell  
            for (Iterator> it1 = cell.iterator(); it1.hasNext(); ) {
                Element eCell = (Element) it1.next();
                // cell        row
                Information.Row.Cell cell1 = new Information.Row.Cell();
                int index = Integer.parseInt(eCell.attributeValue("Index"));
                cell1.setIndex(index);
                int styleid = Integer.parseInt(eCell.attributeValue("StyleID"));
                cell1.setStyleID(styleid);
                if (eCell.attributeValue("MergeAcross") != null) {
                    int mergeacross = Integer.parseInt(eCell.attributeValue("MergeAcross"));
                    cell1.setMergeAcross(mergeacross);
                }
                if (eCell.attributeValue("MergeDown") != null) {
                    int mergedown = Integer.parseInt(eCell.attributeValue("MergeDown"));
                    cell1.setMergeDown(mergedown);
                }
                lcell.add(cell1);//    cell   listlcell 
                if(eCell.element("Data")!=null) {
                    Element data = eCell.element("Data");//  Cell  Data  
                    // data        cell1
                    Information.Row.Cell.Data data1 = new Information.Row.Cell.Data();
                if (data.attributeValue("Ticked")!= null) {
                    int ticked = Integer.parseInt(data.attributeValue("Ticked"));
                    data1.setTicked(ticked);
                }
                    data1.setType(data.attributeValue("Type"));
                    data1.setDat(data.getText());
                    cell1.setData(data1);
                }
            }
            row1.setCell(lcell);
        }
        information.setRow(lrow);// lrow  list   information row   
return information;
    }
}


ExcelAnalysisクラス(excleファイルの書き込み用):
package com.jzcf;

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.*;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;

import java.util.*;


import java.util.List;
import java.util.ArrayList;

import org.apache.poi.ss.usermodel.IndexedColors;

import java.io.File;
import java.io.FileOutputStream;
import java.util.Map;
import java.util.Set;

public class ExcelAnalysis {
    /**
     *   :               row             。
     */
    public static void main(String[] args) throws DocumentException {
        File inputFile = new File("D:\\Work\\a.xml");
        SAXReader reader = new SAXReader();
        Document document = reader.read(inputFile);
        List columnList = XmlReader.getColumn(document);//        
        Map styleMap = XmlReader.getStyle(document);//  style    
        Information information = XmlReader.getData(document);
        //1.    webbook,    Excel  
        HSSFWorkbook wb = new HSSFWorkbook();
        //2.            sheet,  Excell       ,        
        HSSFSheet sheet = wb.createSheet(information.getName());

        for (int i = 0; i < columnList.size(); i++) {//  column         
            sheet.setColumnWidth(i, (int) columnList.get(i).getWidth() * 42);
        }
        //  information  row           
        HSSFRow row = sheet.createRow(0);
        row.setHeight((short) 380);//          31px
        int rownum = information.getRow().size();//    
        CellRangeAddress region1 = new CellRangeAddress(0, 0, (short) 0, (short) 20);//     
        CellRangeAddress region2 = new CellRangeAddress(0, 37, (short) 21, (short) 21);//     
        sheet.addMergedRegion(region1);
        sheet.addMergedRegion(region2);
        for (int i = 1; i < rownum; i++) {
            Row row1 = sheet.createRow(i);
            if (i == 1 || i == 14 || i == 26) {
                row1.setHeight((short) 480);
            }
            //     
            int cellnum = information.getRow().get(i).getCell().size();//         
            List lindex = new ArrayList();
            for (int j = 0; j < cellnum; j++) {//   index    list 
                int index = information.getRow().get(i).getCell().get(j).getIndex();//          
                lindex.add(index);
            }
            for (int j = 0; j < cellnum; j++) {

                int index = information.getRow().get(i).getCell().get(j).getIndex();//          
                int mergeAcross = index - 1;
                if (information.getRow().get(i).getCell().get(j).getMergeAcross() != 0) {
                    mergeAcross += information.getRow().get(i).getCell().get(j).getMergeAcross();//          
                    CellRangeAddress r1 = new CellRangeAddress(i, i, (short) index - 1, (short) mergeAcross);//     
                    sheet.addMergedRegion(r1);
                }
                if (information.getRow().get(i).getCell().get(j).getData() != null) {//         
                    HSSFCell cell = sheet.getRow(i).createCell(lindex.get(j) - 1);
                    String data = information.getRow().get(i).getCell().get(j).getData().getDat();//       data
                    cell.setCellValue(data);
                    int styleID = information.getRow().get(i).getCell().get(j).getStyleID();//           styleid
                    Set> entrySet = styleMap.entrySet();
                    //  Set  
                    Iterator> it1 = entrySet.iterator();
                    while (it1.hasNext()) {
                        //         
                        Map.Entry entry = it1.next();
                        //              key
                        int key = entry.getKey();
                        if (styleID == key) {
                            //              value
                            HSSFFont font = wb.createFont();
                            Style value = entry.getValue();
                            HSSFCellStyle style = wb.createCellStyle();
                            //           
                            style.setVerticalAlignment(VerticalAlignment.TOP);
                            style.setWrapText(true);
                            String horizontal = value.getAlignment().getHorizontal();
                            if (horizontal.equals("Left")) {
                                style.setAlignment(HorizontalAlignment.LEFT);
                            } else if (horizontal.equals("Center")) {
                                style.setAlignment(HorizontalAlignment.CENTER);
                            } else {
                                style.setAlignment(HorizontalAlignment.RIGHT);
                            }
                            for (int k = 0; k < value.getBorders().size(); k++) {//      
                                if (value.getBorders().get(k).getLinestyle() != null) {
                                    if (k == 0) {
                                        style.setBorderBottom(BorderStyle.THIN);
                                    } else if (k == 1) {
                                        style.setBorderTop(BorderStyle.THIN);
                                    } else if (k == 2) {

                                        style.setBorderLeft(BorderStyle.THIN);

                                    } else if (k == 3) {
                                        style.setBorderRight(BorderStyle.THIN);
                                        if (information.getRow().get(i).getCell().get(j).getMergeAcross() != 0) {
                                            mergeAcross = information.getRow().get(i).getCell().get(j).getMergeAcross() + index - 1;//          
                                            CellRangeAddress r1 = new CellRangeAddress(i, i, (short) index - 1, (short) mergeAcross);//
                                            RegionUtil.setBorderTop(BorderStyle.THIN, r1, sheet);
                                            RegionUtil.setBorderBottom(BorderStyle.THIN, r1, sheet);
                                            RegionUtil.setBorderLeft(BorderStyle.THIN, r1, sheet);
                                            RegionUtil.setBorderRight(BorderStyle.THIN, r1, sheet);
                                        }
                                    }
                                }
                            }
                            cell.setCellStyle(style);
                            if (value.getInterior().getPattern() != null) {
                                style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());  //     
                                style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                            }
                            font.setFontName("serif");//    
                            if (value.getFont().getSize() == 16) {
                                font.setFontHeightInPoints((short) 16);//    
                            } else {
                                font.setFontHeightInPoints((short) 10);//    
                            }
                            if (value.getFont().getBold() == 1) {
                                font.setBold(true);
                            }
                            font.setColor(IndexedColors.BLACK.getIndex());
                            style.setFont(font);
                        }

                    }
                }
            }

        }

        FileOutputStream fileOut;
        try {
            fileOut = new FileOutputStream("D:/Work/c.xls");
            wb.write(fileOut);
            fileOut.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("    !");
    }
}


パッケージ依存度:



  4.0.0

  com.jzcf
  xmlwork
  1.0-SNAPSHOT

  xmlwork
  
  http://www.example.com

  
    UTF-8
    1.7
    1.7
      1.2.71
  

  
    
      xml-apis
      xml-apis
      1.3.02
    
    
      xerces
      xercesImpl
      2.6.2-jaxb-1.0.6
    

    
      dom4j
      dom4j
      1.5
    

    
      jaxen
      jaxen
      1.1
    
    
      junit
      junit
      4.11
      test
    
    
      org.apache.poi
      poi-ooxml
      3.17
    
    
      org.apache.poi
      poi
      3.17
    
    
      org.apache.poi
      poi-examples
      3.17
    
    
      org.apache.poi
      poi-excelant
      3.17
    
    
      org.apache.poi
      poi-ooxml-schemas
      3.17
    
    
      org.apache.poi
      poi-scratchpad
      3.17
    
    
      dom4j
      dom4j
      1.6.1
    
    
      stax
      stax-api
      1.0
    
    
      org.apache.xmlbeans
      xmlbeans
      2.6.0
    
    
      org.apache.poi
      poi
      3.17
    

    
      commons-io
      commons-io
      2.0
    
      
          org.jetbrains.kotlin
          kotlin-stdlib-jdk8
          ${kotlin.version}
      
      
          org.jetbrains.kotlin
          kotlin-test
          ${kotlin.version}
          test
      

  

  
    
      
        
        
          maven-clean-plugin
          3.1.0
        
        
        
          maven-resources-plugin
          3.0.2
        
        
          maven-compiler-plugin
          3.8.0
        
        
          maven-surefire-plugin
          2.22.1
        
        
          maven-jar-plugin
          3.0.2
        
        
          maven-install-plugin
          2.5.2
        
        
          maven-deploy-plugin
          2.8.2
        
        
        
          maven-site-plugin
          3.7.1
        
        
          maven-project-info-reports-plugin
          3.0.0
        
      
    
      
          
              org.jetbrains.kotlin
              kotlin-maven-plugin
              ${kotlin.version}
              
                  
                      compile
                      compile
                      
                          compile
                      
                  
                  
                      test-compile
                      test-compile
                      
                          test-compile
                      
                  
              
              
                  1.8
              
          
          
              org.apache.maven.plugins
              maven-compiler-plugin
              
                  
                      compile
                      compile
                      
                          compile
                      
                  
                  
                      testCompile
                      test-compile
                      
                          testCompile
                      
                  
              
          
      
  



以上は私の今回のプログラムの実现の过程とコードで、后で1つの包装したプロジェクトのファイルを放して、必要な友达が自分で取ることができます