ASF Bugzilla – Attachment 2423 Details for
Bug 10548
[PATCH] Unicode Support for excel sheetname.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Unit test for testing BoundSheetRecord
TestBoundSheetRecord.java (text/plain), 6.71 KB, created by
Sergei Kozello
on 2002-07-20 22:45:28 UTC
(
hide
)
Description:
Unit test for testing BoundSheetRecord
Filename:
MIME Type:
Creator:
Sergei Kozello
Created:
2002-07-20 22:45:28 UTC
Size:
6.71 KB
patch
obsolete
> >/* ==================================================================== > * The Apache Software License, Version 1.1 > * > * Copyright (c) 2002 The Apache Software Foundation. All rights > * reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > * are met: > * > * 1. Redistributions of source code must retain the above copyright > * notice, this list of conditions and the following disclaimer. > * > * 2. Redistributions in binary form must reproduce the above copyright > * notice, this list of conditions and the following disclaimer in > * the documentation and/or other materials provided with the > * distribution. > * > * 3. The end-user documentation included with the redistribution, > * if any, must include the following acknowledgment: > * "This product includes software developed by the > * Apache Software Foundation (http://www.apache.org/)." > * Alternately, this acknowledgment may appear in the software itself, > * if and wherever such third-party acknowledgments normally appear. > * > * 4. The names "Apache" and "Apache Software Foundation" and > * "Apache POI" must not be used to endorse or promote products > * derived from this software without prior written permission. For > * written permission, please contact apache@apache.org. > * > * 5. Products derived from this software may not be called "Apache", > * "Apache POI", nor may "Apache" appear in their name, without > * prior written permission of the Apache Software Foundation. > * > * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED > * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES > * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR > * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF > * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND > * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, > * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT > * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > * SUCH DAMAGE. > * ==================================================================== > * > * This software consists of voluntary contributions made by many > * individuals on behalf of the Apache Software Foundation. For more > * information on the Apache Software Foundation, please see > * <http://www.apache.org/>. > */ > >package org.apache.poi.hssf.record; > >import java.io.File; >import java.io.FileInputStream; >import java.io.FileOutputStream; >import java.io.IOException; >import java.io.InputStream; > >import junit.framework.TestCase; > >import org.apache.poi.hssf.eventmodel.HSSFEventFactory; >import org.apache.poi.hssf.eventmodel.HSSFListener; >import org.apache.poi.hssf.eventmodel.HSSFRequest; > >import org.apache.poi.hssf.usermodel.HSSFCell; >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.poifs.filesystem.POIFSFileSystem; > >/** > * Unit test for BoundSheetRecord > * > * @author Sergei Kozello (sergeikozello at mail.ru) > */ > >public class TestBoundSheetRecord > extends TestCase >{ > private String _test_file_path; > private static final String _test_file_path_property = "HSSF.testdata.path"; > > > /** > * Creates new TestStringUtil > * > * @param name > */ > > public TestBoundSheetRecord(String name) > { > super(name); > } > > /** > * getting the path to the test files > */ > > protected void setUp() > throws IOException > { > _test_file_path = System.getProperty( _test_file_path_property ); > } > > /** > * test simple form of getFromUnicode > */ > > public void testCreateExcelFileWithUnicodeNameAndReadTheNameBack() > throws IOException > { > File excelFile = new File( _test_file_path + File.separator + "workbook.xls" ); > try { > String sourceSheetName = "\u0422\u0435\u0441\u0442\u043E\u0432\u0430\u044F " + > "\u0421\u0442\u0440\u0430\u043D\u0438\u0447\u043A\u0430"; > > // > // write test file > // > FileOutputStream out = new FileOutputStream( excelFile ); > try { > > HSSFWorkbook wb = new HSSFWorkbook(); > HSSFSheet s = wb.createSheet(); > > // set the sheet name to HSSF Test > wb.setSheetName(0, sourceSheetName, HSSFWorkbook.ENCODING_UTF_16 ); > // wb.setSheetName(0, "HSSF Test", HSSFWorkbook.ENCODING_COMPRESSED_UNICODE ); > > HSSFRow r = s.createRow(0);; > HSSFCell c = r.createCell((short)0); > c.setCellType(HSSFCell.CELL_TYPE_STRING); > c.setEncoding( HSSFCell.ENCODING_UTF_16 ); > c.setCellValue( "\u0422\u0435\u0441\u0442\u043E\u0432\u0430\u044F" ); > > wb.write( out ); > } > finally { > out.close(); > } > > > String targetSheetName; > // > // read test file > // > FileInputStream fin = new FileInputStream( excelFile ); > try { > POIFSFileSystem poifs = new POIFSFileSystem(fin); > HSSFRequest req = new HSSFRequest(); > NameListener listener = new NameListener(); > req.addListenerForAllRecords( listener ); > HSSFEventFactory factory = new HSSFEventFactory(); > InputStream din = poifs.createDocumentInputStream("Workbook"); > try { > factory.processEvents(req, din); > } > finally { > din.close(); > } > > targetSheetName = listener.getSheetName(); > } > finally { > fin.close(); > } > > > assertEquals( sourceSheetName, targetSheetName ); > } > finally { > excelFile.delete(); > } > } > > > /** > * main > * > * @param ignored_args > */ > > public static void main(String [] ignored_args) > { > System.out.println("Testing record.BoundSheetRecord functionality"); > junit.textui.TestRunner.run(TestBoundSheetRecord.class); > } >}
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 10548
:
2331
|
2332
|
2333
|
2422
| 2423 |
2424
|
2430