简体   繁体   中英

applying styles to a complete row using xssfworkbook in java

Here,I am applying styles to excel,if I apply styles to individual cell it is working but takes lot of time to copy content and apply styles.Here we have option for applying styles to entire row at once using "row.setRowStyle(Style);" but styles are not applicable to excel.
Here is the sample code that I am using

public class WriteDataToExcel {
        public static void main(String[] args) throws IOException {
            XSSFWorkbook wb = new XSSFWorkbook();
            XSSFSheet sheet = wb.createSheet("writetoexcel");
               XSSFFont font = wb.createFont();
                font.setBoldweight((short) 700);
                XSSFCellStyle Style = wb.createCellStyle();
                Style.setFillForegroundColor(new XSSFColor(java.awt.Color.LIGHT_GRAY));
                Style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
                Style.setFont(font);
                Style.setWrapText(true);
                Style.setAlignment(XSSFCellStyle.ALIGN_CENTER);
            for (int r=0;r < 1000; r++ )
            {
                XSSFRow row = sheet.createRow(r);
                //iterating c number of columns
                for (int c=0;c < 25; c++ )
                {
                    XSSFCell cell = row.createCell(c);
                    cell.setCellValue("Hello"); 
                    cell.setCellStyle(Style);
                }
                //row.setRowStyle(Style);
            }
            FileOutputStream fileOut = new FileOutputStream("E:" + File.separator + "WriteToExcel.xlsx");
            wb.write(fileOut);
            fileOut.flush();
            fileOut.close();
        }
}

I just used SXSSFWorkbook instead of XSSFWorkbook

SXSSFWorkbook wb = new SXSSFWorkbook();

SXSSFSheet sheet = (SXSSFSheet) wb.createSheet("writetoexcel");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM