`

Gerry-自定义报表组件

阅读更多

所涉及到的文件列表如下:
ExcelReport.java
TemplateParser.java
ReportUtil.java
Constants.java

 

依赖jar包:
commons-io-1.4.jar
dom4j-1.5.jar
jaxen-1.1.jar

 

配置模板文件:
test_info.xls
test_info.xml

 

 

在大数据量的报表导出中,配合JMS消息队列一起使用!

 

 

(ExcelReport.java)

import java.io.File;   
import java.io.FileOutputStream;   
import java.io.IOException;   
import java.io.OutputStreamWriter;   
import java.io.Writer;   
import java.sql.Timestamp;   
import java.util.Date;   
import java.util.ArrayList;   
import java.util.HashMap;   
import java.util.HashSet;   
import java.util.List;   
import org.apache.commons.io.FileUtils;   
import org.dom4j.Document;   
import org.dom4j.DocumentException;   
import org.dom4j.Element;   
import org.dom4j.io.SAXReader;   
  
public class ExcelReport {   
    // 用于存放对模板对应的XML文件的解析   
    private ArrayList columnList = null;   
  
    private String destpath = "";   
  
    private String dirname = "";   
  
    private int count = 0;   
  
    private String actualDest = "";   
  
    private HashSet sheetSet = new HashSet();   
  
    @SuppressWarnings("unchecked")   
    public ExcelReport(String xlstemplate, String xmltemplate, String dest,String fileFolder, String systemCode){   
        destpath = dest;   
        //创建生成报表的文件夹   
        ReportUtil.createDir("d:/temp/report/result/", fileFolder,systemCode);   
        dirname = xlstemplate.substring(xlstemplate.lastIndexOf("/") + 1,xlstemplate.lastIndexOf("."));   
        actualDest = xlstemplate.substring(0, xlstemplate.lastIndexOf("/") + 1);   
        SAXReader reader = new SAXReader();   
        Document document = null;   
        try {   
            document = reader.read(new File(xlstemplate));   
        } catch (DocumentException e) {   
            e.printStackTrace();   
        }   
        List list = (ArrayList) document.selectNodes("/ss:Workbook/ss:Worksheet");   
        HashSet set = new HashSet();   
        ArrayList sheetList = new ArrayList();   
        for (int i = 0; i < list.size(); i++) {   
            Element node = (Element) list.get(i);   
            if (!set.contains(node)){sheetList.add(node);}   
            set.add(node);   
        }   
        for (int j = 0; j < sheetList.size(); j++) {   
            Element node = (Element) sheetList.get(j);   
            String sheetname = actualDest + dirname + "/sheet" + j + ".txt";   
            try {   
                FileUtils.writeStringToFile(new File(sheetname), node.asXML().toString(), "UTF-8");   
            } catch (IOException e) {   
                e.printStackTrace();   
            }   
        }   
        TemplateParser parser = new TemplateParser();   
        // 对模板进行解析获取数据库字段和列明的关系   
        try {   
            columnList = (ArrayList) parser.templateParser(xmltemplate);   
        } catch (DocumentException e) {   
            e.printStackTrace();   
        }   
        // 将文件头写到一个文件中去   
        Writer writer = null ;   
        try {   
            writer = new OutputStreamWriter(new FileOutputStream(new File(dest)), "utf-8");   
            List list0 = FileUtils.readLines(new File(xlstemplate), "UTF-8");   
            for (int i = 0; i < list0.size(); i++) {   
                String temp = (String) list0.get(i);   
                if (!temp.contains("Worksheet")) {   
                    writer.write(temp + "\n");   
                } else  
                    break;   
            }   
        }catch (IOException e) {   
            e.printStackTrace();   
        }finally{   
            if(writer!=null){   
              try {   
                writer.flush();   
                writer.close();   
              } catch (IOException e) {   
                e.printStackTrace();   
              }   
            }   
        }   
    }  

/**  
     *   
     * @param resultList  
     *            数据集  
     * @param sheet  
     *            在模板中的第几个sheet,只有一个,则为0  
     * @param end  
     *            是否是需要到处的最后一批数据  
     * @return  
     * @throws IOException   
     * @throws IOException  
     */  
    @SuppressWarnings("unchecked")   
    public boolean generateReport(List resultList, int sheet, boolean end, String head_content, String foot_content){   
           
        if(resultList.size()==0&&!end)   
            return true;   
        if(resultList.size()==0&&end)   
        {   
            Writer writer = null ;   
            try{   
                writer = new OutputStreamWriter(new FileOutputStream(new File(destpath), true), "utf-8");   
                writer.write("</Workbook>");   
            }catch (IOException e) {   
                e.printStackTrace();   
            }finally{   
                if(writer!=null){   
                  try {   
                    writer.flush();   
                    writer.close();   
                  } catch (IOException e) {   
                    e.printStackTrace();   
                  }   
                }   
            }   
            return true;   
        }   
           
           
        boolean result = true;   
        if (!sheetSet.contains(sheet) && count == 0) {   
            sheetSet.add(sheet);   
            count++;   
        } else if (sheetSet.contains(sheet) && count != 0) {   
            count++;   
        } else if (!sheetSet.contains(sheet) && count != 0) {   
            sheetSet.add(sheet);   
            count = 0;   
            count++;   
        }   
        //int sheetLength = 0;   
        Writer writer = null ;   
        try {   
            writer = new OutputStreamWriter(new FileOutputStream(new File(destpath), true), "utf-8");   
            List list0 = FileUtils.readLines(new File(actualDest + dirname+ "/sheet" + sheet + ".txt"), "UTF-8");   
            int j = 0;   
            int k = 0;   
            int t = 0;   
            int y = 0;   
            ArrayList tempList = new ArrayList();   
            for (int i = 0; i < list0.size(); i++) {   
                k++;   
                t++;   
                String temp = (String) list0.get(i);   
                if (temp.contains("ss:ExpandedRowCount=")) {   
                    String temp1 = temp.substring(temp.indexOf("ss:ExpandedRowCount="));   
                    String temp2 = temp1.substring(0, temp1.indexOf(" "));   
                    temp = temp.replace(temp2, "");   
                }   
                if (temp.contains("Worksheet") && temp.contains("ss:Name=")) {   
                    String temp1 = temp.substring(temp.indexOf("ss:Name="));   
                    String temp2 = temp1.substring(temp1.indexOf("\"") + 1,temp1.lastIndexOf("\""));   
                    String temp3 = "ss:Name=\"" + temp2 + "_" + count + "\">";   
                    temp = temp.replace(temp1, temp3);   
                }   
                   
                   
                if (temp.contains("</Row>")){j++;}   
                if (temp.contains("</Data>")&&y==0){   
                    y++;   
                    temp = temp.replace("</Data>",(head_content) + "</Data>")+"\n";   
                }   
                if (j < 2)   
                    writer.write(temp + "\n");   
                if (j == 2) {   
                    writer.write(temp + "\n");   
                    break;   
                }   
            }   
            for (int i = k; i < list0.size(); i++) {   
                t++;   
                String temp = (String) list0.get(i);   
                tempList.add(temp);   
                if (temp.contains("</Row>")) {   
                    break;   
                }   
            }   
            HashMap columnMap = null;   
            for (int i = 0; i < columnList.size(); i++) {   
                columnMap = (HashMap) columnList.get(i);   
                if (columnMap != null && columnMap.get("sheet").equals(String.valueOf(sheet))){break;}   
            }  
for (int i = 0; i < resultList.size(); i++) {   
                String temp = "";   
                HashMap map = (HashMap) resultList.get(i);   
                temp += tempList.get(0) + "\n";   
                for (int g = 1; g < tempList.size() - 1; g++) {   
                    String key = Integer.toString(g - 1);   
                    Object obj = map.get(columnMap.get(key));   
                    String type_name = "" ;   
                    if(obj!=null){   
                        type_name = obj.getClass().getSimpleName();   
                    }else{   
                        type_name = "String" ;   
                    }   
                    if(type_name==null){type_name = "String" ;}   
                    String value = "" ;   
                    if(type_name.equals("String")){   
                        value = (String)map.get(columnMap.get(key));   
                    }else if(type_name.equals("Timestamp")){   
                        Timestamp temp_tamp =  (Timestamp)map.get(columnMap.get(key));   
                        value = temp_tamp.toString();   
                    }   
                    if(value==null){value="";}   
                    temp += ((String)tempList.get(g)).replace("</Data>",(value) + "</Data>") + "\n";   
                }   
                temp += tempList.get(tempList.size() - 1) + "\n";   
                writer.write(temp);   
                writer.flush();   
            }   
            //加入尾部的信息   
            writer.write("<Row><Cell><Data ss:Type=\"String\">"+foot_content+"</Data></Cell></Row>");   
            for (int i = t; i < list0.size(); i++) {   
                writer.write((String) list0.get(i) + "\n");   
            }   
            if (end){writer.write("</Workbook>");}   
        }catch (IOException e) {   
            result = false;   
            e.printStackTrace();   
        }finally{   
            if(writer!=null){   
                try{   
                    writer.flush();   
                    writer.close();   
                 } catch (IOException e) {   
                    e.printStackTrace();   
                 }   
            }   
        }   
        return result;   
    }  
/**  
     *   
     * 用于测试的方法(不启用)  
     * @param args  
     * @throws Exception  
     */  
    public static void main(String[] args) throws Exception {   
           
        ArrayList<HashMap> list = new ArrayList<HashMap>();   
        Timestamp log_time_local2 = new Timestamp(new Date().getTime());   
        for (int i = 0; i <= 6550; i++) {   
            HashMap<String,Object> map = new HashMap<String,Object>();   
            map.put("id", "id"+i);   
            map.put("value1", "value1:"+i);   
            map.put("value2", "value2:"+i);   
            map.put("value3", "value3:"+i);   
            map.put("value4", "value4:"+i);   
            map.put("value5", "value5:"+i);   
            map.put("value6", log_time_local2);   
            map.put("value7", "value7:"+i);   
            map.put("value8", "value8:"+i);   
            map.put("value9", "value9:"+i);   
            map.put("value10","value10:"+i);   
            list.add(map);   
        }   
        //int record_size = new Integer(Constants.RECORD_SIZE);   
        //int max_sheet = Constants.MAX_SHEET;   
        //int max_file = Constants.MAX_FILE;   
        ExcelReport report = new ExcelReport("d:/temp/report/template/test_info.xls","d:/temp/report/template/test_info.xml", "d:/temp/report/result/2010-07-14/project1/testinfo-0000001.xls","2010-07-14","project1");   
        report.generateReport(list, 0, false, "select 1 from sysibm.sysdummy1", "select 2 from sysibm.sysdummy1");   
        report.generateReport(list, 0, true, "select 1 from sysibm.sysdummy1", "select 2 from sysibm.sysdummy1");   
        //采用追加SHEET的方式对数据进行分批处理(注意Excel 一个sheet页最大的数据量在65535条数据,超过后不能打开)   
        //report.generateReport(list, 0, true);   
        //report.generateReport(list, 0, false);   
        //report.generateReport(list, 0, false);   
        //report.generateReport(list, 0, false);   
        //report.generateReport(list, 0, false);   
        //report.generateReport(list2, 1, false);   
        //report.generateReport(list2, 1, false);   
        //report.generateReport(list2, 1, false);   
        //report.generateReport(list2, 1, false);   
        //report.generateReport(list2, 1, true);   
        //System.out.println(new Integer(Constants.RECORD_SIZE) * new Integer(Constants.MAX_SHEET));   
           
        //文件目录 d:/temp/report/  (result,template)   
        System.out.println("Complete!");   
    }   
}  

 

 

 

   TemplateParser.java

 

  

import java.io.File;   
import java.util.ArrayList;   
import java.util.HashMap;   
import java.util.Iterator;   
import java.util.List;   
  
import org.dom4j.Document;   
import org.dom4j.DocumentException;   
import org.dom4j.Element;   
import org.dom4j.io.SAXReader;   
  
public class TemplateParser {   
      
    public List templateParser(String template) throws DocumentException{   
           
        SAXReader reader = new SAXReader();   
        List resultList =new ArrayList();   
        Document document = reader.read(new File(template));   
        List list0 = document.selectNodes("/report/report_content");   
        for(int i=0;i<list0.size();i++){   
            Element value0=(Element)list0.get(i);   
            String tempValue=value0.attributeValue("sheet");   
            List list = document.selectNodes("/report/report_content[@sheet="+tempValue+"]/property");   
            Iterator it = list.iterator();   
       
            String row="";   
            HashMap map=new HashMap();   
            map.put("sheet", tempValue);   
            while (it.hasNext()) {   
                Element value = (Element) it.next();   
                map.put(value.attributeValue("column"), value.attributeValue("name"));   
                row=value.attributeValue("row");   
            }   
            map.put("row", row);   
            resultList.add(map);   
        }   
        return resultList;   
    }   
    /**  
     * @param args  
     * @throws DocumentException   
     */  
    public static void main(String[] args) throws DocumentException {   
        TemplateParser p=new TemplateParser();   
        List list1 = p.templateParser("d:/temp/report/template/client_info.xml");   
        //System.out.println(list1);   
    }   
  
}  

 

 

    ReportUtil.java

   

import java.io.File;   
import java.util.ArrayList;   
import java.util.Arrays;   
import java.util.List;   
  
public class ReportUtil {   
  
    private static File m_root; // 记录要删除的路径   
    private static ArrayList m_dirs;// 删除的路径下的所有文件和文件夹   
  
    /**  
     * 创建文件夹  
     */  
    public static void createDir(String path , String folder1,String folder2){   
        createDir(path+folder1);   
        createDir(path+folder1+File.separator + folder2);   
    }   
       
    /**  
     * 创建文件夹  
     */  
    public static void createDir(String path) {   
        File dir = new File(path);   
        if (!dir.exists()) {   
            System.out.println("dir not exist and  need create :" + path);   
            dir.mkdir();   
        }   
    }   
  
    /**  
     * 删除文件夹方法  
     */  
    public static void deleteDirs(String path) {   
        deleteDirs(new File(path));   
    }   
       
    /**  
     * 删除文件夹方法  
     * dir  
     * 要删除的文件夹路径(java.io.File类型)  
     */  
    public static void deleteDirs(java.io.File dir) {   
        try {   
            m_root = dir;   
            m_dirs = new ArrayList();   
  
            if (!m_root.isDirectory()) { // 判断输入的是否为路径   
                System.out.println(m_root.toString() + " 不是路径");   
            } else {   
                // 输出m_dirs中记录的值   
                // for(int i=0 ; i<m_dirs.size() ; i++){   
                // System.out.println(((File)m_dirs.get(i)).toString());   
                // }   
                m_dirs.add(m_root);   
  
                visitAll(m_root); // 获取指定路径下的所有文件已经文件夹(递归调用)   
                rootDelete(); // 删除list中的所有文件(倒叙循环删除)   
            }   
        } catch (Exception ex) {   
            System.out.println("error in deleteDirs : " + ex.getMessage());   
        }   
    }   
  
    /**  
     * 删除文件或文件夹 注意:使用倒叙删除,先删除文件,然后删除空文件夹  
     */  
    private static void rootDelete() {   
        try {   
            if (m_dirs != null) {   
                // 使用倒叙循环删除(先删除文件,再删除文件夹)   
                for (int i = m_dirs.size() - 1; i >= 0; i--) {   
                    File f = (File) m_dirs.remove(i);// 获取之后删除list中的数据   
                    // 删除数据   
                    if (!f.delete()) {   
                        System.out.println("文件路径:" + f.toString() + " 不存在");   
                    }   
                }   
            } else {   
                System.out.println("获取文件list列表(m_dirs)为空");   
            }   
        } catch (Exception ex) {   
            System.out.println("error in rootDelete : " + ex.getMessage());   
        }   
    }  
/**  
     * 获取所有文件和文件夹,存储在m_dirs中 注意:递归调用  
     *   
     * @param tempRoot  
     *            文件路径  
     */  
    private static void visitAll(File tempRoot) {   
        try {   
            // 获取指定路径下的所有文件   
            File[] dirs = tempRoot.listFiles();   
  
            if (dirs != null) {   
                // 将文件数组转换成List对象   
                List dirslist = Arrays.asList(dirs);   
  
                // 将dirslist完全添加到m_dirs中   
                m_dirs.addAll(dirslist);   
  
                // 递归调用   
                for (int i = 0; i < dirslist.size(); i++) {   
                    visitAll((File) dirslist.get(i));   
                }   
            }   
        } catch (Exception ex) {   
            System.out.println("error in visitAll : " + ex.getMessage());   
        }   
    }   
}  

 

 

   

    Constants.java

    

public class Constants {   
  
    /**  
     * 报表的sheet页信息  
     */  
    public final static String REPORT_QUEUE_SHEET_NUMBER = "sheet_number";   
       
    /**  
     * 报表的多文件信息  
     */  
    public final static String REPORT_QUEUE_MULTI_FILE = "multi_file";   
       
    /**  
     * 报表任务的申请时间  
     */  
    public final static String REPORT_QUEUE_APPLY_TIME = "apply_time";   
  
    /**  
     *   
     * 从配置文件查找,如果找不到,返回null  
     *   
     * @param key  
     * @return  
     */  
  
    /**  
     * 生成的报表每个sheet页放置的数量  
     */  
    public  static String RECORD_SIZE;//   
    /**  
     * 每个报表最多可生成sheet页的数量  
     */  
    public  static int MAX_SHEET;//   
    /**  
     * 每个报表任务最多可生成的报表数量  
     */  
    public  static int MAX_FILE;//   
    /**  
     * 可写入数据的报表文件大小的最大值<最好小于9M=9437184>  
     */  
    public  static int REPORT_FILE_READ_SIZE;//   
}  

 

  

    test_info.xls

   

<?xml version="1.0"?>  
<?mso-application progid="Excel.Sheet"?>  
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"  
 xmlns:o="urn:schemas-microsoft-com:office:office"  
 xmlns:x="urn:schemas-microsoft-com:office:excel"  
 xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"  
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"  
 xmlns:html="http://www.w3.org/TR/REC-html40">  
 <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">  
  <LastAuthor>ago</LastAuthor>  
  <Created>2010-01-14T12:08:11Z</Created>  
  <LastSaved>2010-03-12T09:30:16Z</LastSaved>  
  <Version>11.6568</Version>  
 </DocumentProperties>  
 <CustomDocumentProperties xmlns="urn:schemas-microsoft-com:office:office">  
  <sflag dt:dt="string">1268365527</sflag>  
 </CustomDocumentProperties>  
 <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">  
  <WindowHeight>9150</WindowHeight>  
  <WindowWidth>14940</WindowWidth>  
  <WindowTopX>360</WindowTopX>  
  <WindowTopY>270</WindowTopY>  
  <AcceptLabelsInFormulas/>  
  <ProtectStructure>False</ProtectStructure>  
  <ProtectWindows>False</ProtectWindows>  
 </ExcelWorkbook>  
 <Styles>  
  <Style ss:ID="Default" ss:Name="Normal">  
   <Alignment ss:Vertical="Bottom"/>  
   <Borders/>  
   <Font ss:FontName="Helv" x:Family="Swiss"/>  
   <Interior/>  
   <NumberFormat/>  
   <Protection/>  
  </Style>  
  <Style ss:ID="s21" ss:Name="常规_sheet">  
   <Alignment ss:Vertical="Center"/>  
   <Borders/>  
   <Font ss:FontName="FrutigerNext LT Regular" x:Family="Swiss" ss:Size="12"/>  
   <Interior/>  
   <NumberFormat/>  
   <Protection/>  
  </Style>  
  <Style ss:ID="s23" ss:Parent="s21">  
   <Font ss:FontName="FrutigerNext LT Regular" x:Family="Swiss" ss:Size="9"/>  
  </Style>  
  <Style ss:ID="s24" ss:Parent="s21">  
   <Font ss:FontName="FrutigerNext LT Regular" x:Family="Swiss" ss:Size="9"/>  
   <NumberFormat ss:Format="@"/>  
  </Style>  
<Style ss:ID="s25">  
   <Alignment ss:Vertical="Center"/>  
   <Borders>  
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>  
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>  
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>  
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>  
   </Borders>  
   <Font ss:FontName="宋体" x:CharSet="134" ss:Size="9"/>  
  </Style>  
  <Style ss:ID="s26">  
   <Font ss:FontName="FrutigerNext LT Regular" x:Family="Swiss" ss:Size="9"/>  
   <NumberFormat ss:Format="@"/>  
  </Style>  
  <Style ss:ID="s27">  
   <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1"/>  
   <Borders>  
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>  
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>  
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>  
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>  
   </Borders>  
   <Font ss:FontName="宋体 (serif)" x:CharSet="134" ss:Size="9" ss:Bold="1"/>  
   <Interior ss:Color="#C0C0C0" ss:Pattern="Solid"/>  
  </Style>  
  <Style ss:ID="s28">  
   <Alignment ss:Horizontal="Center" ss:Vertical="Center"/>  
   <Borders>  
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>  
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>  
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>  
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>  
   </Borders>  
   <Font ss:FontName="FrutigerNext LT Regular" x:Family="Swiss" ss:Size="9"/>  
   <Interior ss:Color="#FFFF99" ss:Pattern="Solid"/>  
  </Style>  
  <Style ss:ID="s29">  
   <Alignment ss:Horizontal="Center" ss:Vertical="Center"/>  
   <Borders>  
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>  
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>  
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>  
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>  
   </Borders>  
   <Font ss:FontName="宋体" x:CharSet="134" ss:Size="9" ss:Bold="1"/>  
   <Interior ss:Color="#C0C0C0" ss:Pattern="Solid"/>  
   <Protection ss:Protected="0"/>  
  </Style>  
 </Styles>  
<Worksheet ss:Name="Sheet1">  
  <Table ss:ExpandedColumnCount="11" ss:ExpandedRowCount="4" x:FullColumns="1"  
   x:FullRows="1" ss:StyleID="s23" ss:DefaultColumnWidth="54"  
   ss:DefaultRowHeight="12">  
   <Column ss:StyleID="s23" ss:AutoFitWidth="0" ss:Width="60" ss:Span="5"/>  
   <Column ss:Index="7" ss:StyleID="s23" ss:AutoFitWidth="0" ss:Width="87.75"/>  
   <Column ss:StyleID="s23" ss:AutoFitWidth="0" ss:Width="108.75"/>  
   <Column ss:StyleID="s23" ss:AutoFitWidth="0" ss:Width="60"/>  
   <Column ss:StyleID="s24" ss:AutoFitWidth="0" ss:Width="127.5"/>  
   <Column ss:StyleID="s24" ss:AutoFitWidth="0" ss:Width="141"/>  
   <Row ss:AutoFitHeight="0" ss:Height="15.75">  
    <Cell ss:StyleID="s25"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s25"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s25"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s25"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s25"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s25"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s25"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s25"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s25"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s26"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s26"><Data ss:Type="String"> </Data></Cell>  
   </Row>  
   <Row ss:AutoFitHeight="0" ss:Height="15">  
    <Cell ss:StyleID="s27"><Data ss:Type="String">id</Data></Cell>  
    <Cell ss:StyleID="s27"><Data ss:Type="String">值1</Data></Cell>  
    <Cell ss:StyleID="s27"><Data ss:Type="String">值2</Data></Cell>  
    <Cell ss:StyleID="s27"><Data ss:Type="String">值3</Data></Cell>  
    <Cell ss:StyleID="s27"><Data ss:Type="String">值4</Data></Cell>  
    <Cell ss:StyleID="s27"><Data ss:Type="String">值5</Data></Cell>  
    <Cell ss:StyleID="s27"><Data ss:Type="String">值6</Data></Cell>  
    <Cell ss:StyleID="s27"><Data ss:Type="String">值7</Data></Cell>  
    <Cell ss:StyleID="s27"><Data ss:Type="String">值8</Data></Cell>  
    <Cell ss:StyleID="s27"><Data ss:Type="String">值9</Data></Cell>  
    <Cell ss:StyleID="s27"><Data ss:Type="String">值10</Data></Cell>  
   </Row>
<Row ss:AutoFitHeight="0" ss:Height="14.25">  
    <Cell ss:StyleID="s28"><Data ss:Type="String">  </Data></Cell>  
    <Cell ss:StyleID="s28"><Data ss:Type="String">  </Data></Cell>  
    <Cell ss:StyleID="s28"><Data ss:Type="String">  </Data></Cell>  
    <Cell ss:StyleID="s28"><Data ss:Type="String">  </Data></Cell>  
    <Cell ss:StyleID="s28"><Data ss:Type="String">  </Data></Cell>  
    <Cell ss:StyleID="s28"><Data ss:Type="String">  </Data></Cell>  
    <Cell ss:StyleID="s28"><Data ss:Type="String">  </Data></Cell>  
    <Cell ss:StyleID="s28"><Data ss:Type="String">  </Data></Cell>  
    <Cell ss:StyleID="s28"><Data ss:Type="String">  </Data></Cell>  
    <Cell ss:StyleID="s28"><Data ss:Type="String">  </Data></Cell>  
    <Cell ss:StyleID="s28"><Data ss:Type="String">  </Data></Cell>  
   </Row>  
   <Row ss:AutoFitHeight="0">  
    <Cell ss:StyleID="s29"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s29"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s29"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s29"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s29"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s29"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s29"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s29"/>  
    <Cell ss:StyleID="s29"/>  
    <Cell ss:StyleID="s29"><Data ss:Type="String"> </Data></Cell>  
    <Cell ss:StyleID="s29"><Data ss:Type="String"> </Data></Cell>  
   </Row>  
  </Table>  
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">  
   <PageSetup>  
    <Header x:Data="&amp;L&amp;C&amp;F&amp;R&amp;&quot;宋体,常规&quot;文档密级:"/>  
    <Footer x:Data="&amp;L&amp;D&amp;&amp;R第&amp;P页,共&amp;N页"/>  
   </PageSetup>  
   <Unsynced/>  
   <Print>  
    <ValidPrinterInfo/>  
    <PaperSizeIndex>9</PaperSizeIndex>  
    <HorizontalResolution>600</HorizontalResolution>  
    <VerticalResolution>600</VerticalResolution>  
   </Print>  
   <Selected/>  
   <Panes>  
    <Pane>  
     <Number>3</Number>  
     <ActiveRow>15</ActiveRow>  
     <ActiveCol>9</ActiveCol>  
    </Pane>  
   </Panes>  
   <ProtectObjects>False</ProtectObjects>  
   <ProtectScenarios>False</ProtectScenarios>  
  </WorksheetOptions>  
 </Worksheet>  
</Workbook>  

 

  

    test_info.xml

  

<?xml version="1.0" encoding="UTF-8"?>  
<report templet="test_info.xls">  
  
    <!--表头部分  start_row为起始行号 row_height为表头的总行数 column-width为表头的列宽 -->  
    <report_header start_row="0" row_height="2"  column-width="4">  
        <!--  name对应sql语句中查询的列名 column为报表模板中的列号 row为报表模板中的列号 -->  
        <property name="1"  column="0" row="0"/>  
           
    </report_header>  
  
    <!--表中部分  start_row为起始行号 start_column为起始列号 row_height为循环行的高度 column-width为表中的列宽(即循环行的最后一列的位置) -->  
    <report_content sheet="0" start_row="2" start_column="0"  row_height="1" column-width="17">  
  
        <property name="id"  column="0" row="2"/>  
        <property name="value1"    column="1" row="2"/>  
        <property name="value2"    column="2" row="2"/>  
        <property name="value3"    column="3" row="2"/>  
        <property name="value4"    column="4" row="2"/>  
                             <property name="value5"    column="5" row="2"/>  
        <property name="value6"    column="6" row="2"/>  
        <property name="value7"    column="7" row="2"/>  
        <property name="value8"    column="8" row="2"/>  
        <property name="value9"    column="9" row="2"/>  
        <property name="value10"    column="10" row="2"/>  
           
    </report_content>  
  
    <!--表头部分  start_row为起始行号 row_height为表尾的总行数 column-width为表尾的列宽 -->  
    <report_footer start_row="3" row_height="1" column-width="17">  
        <property name="1"     column="0" row="3"/>  
    </report_footer>  
       
    <!---->  
</report>  

 

 

    至此完毕!

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics