In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
How to operate java Excel, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
1. Write Excel
1.1 documents related to the introduction of Excel
Import java.io.FileOutputStream;import java.util.ArrayList;import java.util.Date;import java.util.HashMap;import java.util.List;import java.util.Map;import org.apache.poi.hssf.usermodel.HSSFCell;import org.apache.poi.hssf.usermodel.HSSFCellStyle;import org.apache.poi.hssf.usermodel.HSSFDataFormat;import org.apache.poi.hssf.usermodel.HSSFRow;import org.apache.poi.hssf.usermodel.HSSFSheet;import org.apache.poi.hssf.usermodel.HSSFWorkbook Import org.apache.poi.ss.usermodel.CreationHelper
1.2 relevant practical methods:
Public static void wirteExcel () throws Exception {/ / create a workbook, that is, an excel file, and then create a sheet HSSFWorkbook wb=new HSSFWorkbook (); HSSFSheet sheet=wb.createSheet ("first sheet"); / / create a line HSSFRow row=sheet.createRow (0) in sheet / / write various types of data in the row row.createCell (0) .setCellValue (true); row.createCell (1). SetCellValue ("Zhong Linsen"); row.createCell (2) .setCellValue (23) / / set to retain two decimal places HSSFCell cell=row.createCell (3); cell.setCellValue (6000); HSSFCellStyle cellStyle = wb.createCellStyle () CellStyle.setDataFormat (HSSFDataFormat.getBuiltinFormat ("0.00")); cell.setCellStyle (cellStyle) / / data in write date format requires special processing (this is a simple processing method) CreationHelper createHelper=wb.getCreationHelper (); HSSFCellStyle style=wb.createCellStyle () Style.setDataFormat (createHelper.createDataFormat (). GetFormat ("yyyy-MM-dd")); cell=row.createCell (4); cell.setCellValue (new Date ()); cell.setCellStyle (style) / / finally write back to disk FileOutputStream out=new FileOutputStream ("E:\\ excel write data .xls"); wb.write (out); out.close () System.out.println ("finished!");} public static void writeExcelList (List title,String sheetName, String filepath,List list) {/ / create a workbook, that is, an excel file, and then create a sheet HSSFWorkbook wb = new HSSFWorkbook () in that file; HSSFSheet sheet = wb.createSheet (sheetName) / / the header generates HSSFRow row_0 = sheet.createRow (0); for (int job0witj
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.