Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Export function of complex excel File by Easypoi

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "how Easypoi implements the export function of complex excel files". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The reason why I use Easypoi is that it can directly fill the data based on the existing template to achieve excel generation, and the template product has been given, so you only need to make minor modifications to use it. The modified template is shown in the figure:

Note that {{$fe: is to loop through listmap variables to populate data rows, while others are similar placeholders, which are easy to understand

/ / the code simply corresponds the placeholder of the template to the variable Map map = new HashMap (); map.put ("code", customer.getCode ()); map.put ("name", customer.getName ()); map.put ("mobile", customer.getMobile ()); map.put ("membershipGrade", customer.getMembershipGrade ()); map.put ("zzyMembershipGrade", customer.getZzyMembershipGrade ()) Map.put ("addressComplete", customer.getAddressComplete ()); List listMap = new ArrayList (); map.put ("maplist", listMap); SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss"); for (MainOrderSubOrderFinanceResult financeResult: mainOrderSubOrderFinanceResults) {Map lm = new HashMap (); lm.put ("orderCode", financeResult.getOrderCode ()) Lm.put ("payStatusDesc", financeResult.getPayStatusDesc ()); lm.put ("settlementTypeDesc", financeResult.getSettlementTypeDesc ()); lm.put ("billDate", dateFormat.format (financeResult.getBillDate (); lm.put ("totalAmount", financeResult.getTotalAmount (). StripTrailingZeros (). ToPlainString ()); lm.put ("discountAmount", financeResult.getDiscountAmount (). StripTrailingZeros (). ToPlainString ()) Lm.put ("amount", financeResult.getAmount (). StripTrailingZeros (). ToPlainString ()); lm.put ("payAmount", financeResult.getPayAmount (). StripTrailingZeros (). ToPlainString ()); lm.put ("amountPaid", financeResult.getAmountPaid (). StripTrailingZeros (). ToPlainString ()); listMap.add (lm); sumTotalAmount = sumTotalAmount.add (financeResult.getTotalAmount ()) SumDiscountAmount = sumDiscountAmount.add (financeResult.getDiscountAmount ()); sumAmount = sumAmount.add (financeResult.getAmount ()); sumPayAmount = sumPayAmount.add (financeResult.getPayAmount ()); sumAmountPaid = sumAmountPaid.add (financeResult.getAmountPaid ());} map.put ("sumTotalAmount", sumTotalAmount); map.put ("sumDiscountAmount", sumDiscountAmount); map.put ("sumAmount", sumAmount) Map.put ("sumPayAmount", sumPayAmount); map.put ("sumAmountPaid", sumAmountPaid); / / generate temporary template files String url= ""; try {File temp = File.createTempFile ("exportCreditBillResult", ".xlsx"); FileUploadHelper.inputStream2File (this.getClass (). GetClassLoader (). GetResourceAsStream ("exportCreditBillResult.xlsx"), temp); url=temp.getAbsolutePath () Temp.deleteOnExit ();} catch (IOException e) {} TemplateExportParams params = new TemplateExportParams (url); Workbook workbook = ExcelExportUtil.exportExcel (params, map)

There is a key point to do this function:

Since the TemplateExportParams constructor only supports the incoming file path, and the template file path directly passed into the resource will have a problem in the online environment (no problem locally), so you need to use getResourceAsStream to read and generate a temporary file, and then pass in the temporary file url

This is the end of the introduction of "how Easypoi implements the export function of complex excel files". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report