ASF Bugzilla – Attachment 32475 Details for
Bug 57517
[PATCH] Wrong result when calling HSSFOptimiser.optimiseCellStyles on workbook that uses user defined styles
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
test case
TestBug57517.java (text/x-java), 5.51 KB, created by
Akira Shiratsuki
on 2015-02-14 16:03:27 UTC
(
hide
)
Description:
test case
Filename:
MIME Type:
Creator:
Akira Shiratsuki
Created:
2015-02-14 16:03:27 UTC
Size:
5.51 KB
patch
obsolete
>/* ==================================================================== > Licensed to the Apache Software Foundation (ASF) under one or more > contributor license agreements. See the NOTICE file distributed with > this work for additional information regarding copyright ownership. > The ASF licenses this file to You under the Apache License, Version 2.0 > (the "License"); you may not use this file except in compliance with > the License. You may obtain a copy of the License at > > http://www.apache.org/licenses/LICENSE-2.0 > > Unless required by applicable law or agreed to in writing, software > distributed under the License is distributed on an "AS IS" BASIS, > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > See the License for the specific language governing permissions and > limitations under the License. >==================================================================== */ >package org.apache.poi.hssf.usermodel; > >import java.io.File; >import java.io.FileNotFoundException; >import java.io.FileOutputStream; >import java.io.IOException; > >import org.apache.poi.hssf.util.HSSFColor; >import org.apache.poi.hssf.util.HSSFColor.RED; >import org.apache.poi.ss.usermodel.CellStyle; >import org.apache.poi.ss.usermodel.Color; >import org.apache.poi.ss.usermodel.IndexedColors; >import org.apache.poi.ss.usermodel.Workbook; > >import junit.framework.TestCase; > >public class TestBug57517 extends TestCase { > private String tmpDirName; > > @Override > protected void setUp() { > > tmpDirName = System.getProperty("java.io.tmpdir"); > } > public void testBug57517() throws IOException { > int i; > int cnt, new_cnt; > int obj_cnt; > HSSFCellStyle s = null; > HSSFWorkbook wb = new HSSFWorkbook(); > FileOutputStream out; > > obj_cnt = cnt = wb.getNumCellStyles(); > > HSSFSheet sheet = wb.createSheet(); > HSSFRow row; > > //Set CellStyle and RowStyle and ColumnStyle > > for (i = 0; i < 2; i++) > sheet.createRow(i); > > // Create a test font and style, and use them > for (i = 0; i < 3; i++) { > // Set Cell Color : Yellow > row = sheet.getRow(0); > row.createCell(i).setCellStyle( > createColorStyle(wb, IndexedColors.GREEN.getIndex())); > obj_cnt++; > > // Set Column Color : Red > sheet.setDefaultColumnStyle(i + 3, > createColorStyle(wb, IndexedColors.RED.getIndex())); > obj_cnt++; > > // Set Row Color : Blue > row = sheet.createRow(i + 3); > row.setRowStyle(createColorStyle(wb, IndexedColors.BLUE.getIndex())); > obj_cnt++; > > if (i == 0) { > // Set cell color : +2(user style + proxy of it) > s = (HSSFCellStyle) createColorStyle(wb, > IndexedColors.YELLOW.getIndex()); > s.setUserStyleName("user define"); > obj_cnt += 2; > } > > row = sheet.getRow(1); > row.createCell(i).setCellStyle(s); > > } > > //Set CellStyle and RowStyle and ColumnStyle > for (i = 9; i < 11; i++) > sheet.createRow(i); > > // Create a test font and style, and use them > for (i = 3; i < 6; i++) { > // Set Cell Color : Yellow > row = sheet.getRow(0 + 9); > row.createCell(i - 3).setCellStyle( > createColorStyle(wb, IndexedColors.GREEN.getIndex())); > obj_cnt++; > > // Set Column Color : Red > sheet.setDefaultColumnStyle(i + 3, > createColorStyle(wb, IndexedColors.RED.getIndex())); > obj_cnt++; > > // Set Row Color : Blue > row = sheet.createRow(i + 3); > row.setRowStyle(createColorStyle(wb, IndexedColors.BLUE.getIndex())); > obj_cnt++; > > if (i == 3) { > // Set cell color : +2(user style + proxy of it) > s = (HSSFCellStyle) createColorStyle(wb, > IndexedColors.YELLOW.getIndex()); > s.setUserStyleName("user define2"); > obj_cnt += 2; > } > > row = sheet.getRow(1 + 9); > row.createCell(i - 3).setCellStyle(s); > > } > > new_cnt = wb.getNumCellStyles(); > assertEquals(obj_cnt, new_cnt); > > out = new FileOutputStream(new File(tmpDirName, "out.xls")); > wb.write(out); > out.close(); > > // Optimise styles > HSSFOptimiser.optimiseCellStyles(wb); > > > out = new FileOutputStream(new File(tmpDirName, "out_optimised.xls")); > wb.write(out); > out.close(); > > //Copmare ColumnStyles > assertEquals(sheet.getColumnStyle(3), sheet.getColumnStyle(4)); > > //Copmare RowStyles > assertEquals(sheet.getRow(3).getRowStyle(), sheet.getRow(4).getRowStyle()); > > //Conferim user style name > assertEquals(sheet.getRow(1).getCell(1).getCellStyle().getParentStyle().getUserStyleName(), "user define"); > > //Conferim user style name > assertEquals(sheet.getRow(10).getCell(1).getCellStyle().getParentStyle().getUserStyleName(), "user define2"); > > > // RED + BLUE + GREEN + YELLOW(2*2) > obj_cnt = cnt + 3 + 2 * 2; > new_cnt = wb.getNumCellStyles(); > assertEquals(obj_cnt, new_cnt); > > } > > private CellStyle createColorStyle(Workbook wb, short c) { > CellStyle cs = wb.createCellStyle(); > cs.setFillPattern(CellStyle.SOLID_FOREGROUND); > cs.setFillForegroundColor(c); > return cs; > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 57517
:
32415
|
32416
|
32466
|
32474
|
32475
|
32476
|
32477
|
32478
|
32479
|
32480
|
32481