Giter Site home page Giter Site logo

file-common's Introduction

文件相关处理

  • excel文件导出

  • csv文件导出

  • txt文件导出

  • 默认格式导出

  • pdf导出,支持url以及html文件

    <dependency>  
        <groupId>org.ifaster.file</groupId>  
        <artifactId>file-common</artifactId>  
        <version>${file-common.version}</version>  
    </dependency>
    

    demo

    
    public class FileExportTest {
    
    private static String path = "/Users/xxxxx/Downloads";
    private static String name = "test";
    
    public static void main(String[] args) throws Exception {
        List<Person> personList = new ArrayList<>();
        for (int i=0; i<10; i++) {
            Person person = new Person();
            person.setCreateDate(new Date());
            person.setName("测试" + i);
            person.setPay(1.009);
            person.setPayAmount(new BigDecimal(1.0098));
            person.setPhone("123456789");
            personList.add(person);
        }
        FileExporterUtil.export(personList, path+"\\"+name);
    }
    
    @Data
    @Exporter(suffix = SuffixEnum.TXT)
    @Exporter(suffix = SuffixEnum.CSV)
    @Exporter(suffix = SuffixEnum.EXCEL, rowAccessWindowSize = 1000)
    public static class Person {
        @Column(header = "姓名")
        private String name;
        @Column(header = "手机号")
        private String phone;
        @Column(header = "创建时间", format = "yyyy-MM-dd HH:mm:ss")
        private Date createDate;
        @Column(header = "支付金额", format = "0.00")
        private double pay;
        @Column(header = "剩余金额", format = "0.00", index = -1)
        private BigDecimal payAmount;
    }
    }
    

    pdf生成

        public class PdfUtilTest {
         
            private static String html = "/Users/xxxxx/Downloads/order.html";
            private static String pdf = "/Users/xxxxx/Downloads/order.pdf";
         
            public static void main(String[] args) {
                try {
                    File file = new File(html);
                    BufferedReader reader = new BufferedReader(new FileReader(file));
                    StringBuilder content = new StringBuilder();
                    String line = null;
                    while ((line = reader.readLine()) != null) {
                        content.append(line);
                    }
                    reader.close();
                    PdfUtil.html2PdfFromString(content.toString(), "/u01/font/simsun.ttc", pdf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    

file-common's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.