TestUnicodeWorkbook.cs :  » GUI » NPOI » TestCases » HSSF » UserModel » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » NPOI 
NPOI » TestCases » HSSF » UserModel » TestUnicodeWorkbook.cs
/*
* 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.
*/
namespace TestCases.HSSF.UserModel{
    using System;
    using System.IO;
    using NPOI.HSSF.UserModel;
    using NPOI.Util;
    using NPOI.SS.UserModel;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class TestUnicodeWorkbook
    {

        public TestUnicodeWorkbook()
        {

        }

        /** Tests that all of the unicode capable string fields can be set, written and then read back
         * 
         *
         */
        //[TestMethod]
        //public void TestUnicodeInAll()
        //{
        //    HSSFWorkbook wb = new HSSFWorkbook();
        //    //Create a unicode dataformat (contains euro symbol)
        //    DataFormat df = wb.CreateDataFormat();
        //    String formatStr = "_([$\u20ac-2]\\\\\\ * #,##0.00_);_([$\u20ac-2]\\\\\\ * \\\\\\(#,##0.00\\\\\\);_([$\u20ac-2]\\\\\\ *\\\"\\-\\\\\"??_);_(@_)";
        //    short fmt = df.GetFormat(formatStr);

        //    //Create a unicode sheet name (euro symbol)
        //    NPOI.SS.UserModel.Sheet s = wb.CreateSheet("\u20ac");

        //    //Set a unicode header (you guessed it the euro symbol)
        //    HSSFHeader h = s.Header;
        //    h.Center = ("\u20ac");
        //    h.Left = ("\u20ac");
        //    h.Right = ("\u20ac");

        //    //Set a unicode footer
        //    HSSFFooter f = s.Footer;
        //    f.Center = ("\u20ac");
        //    f.Left = ("\u20ac");
        //    f.Right = ("\u20ac");

        //    Row r = s.CreateRow(0);
        //    Cell c = r.CreateCell(1);
        //    c.SetCellValue(12.34);
        //    c.CellStyle.DataFormat = (fmt);

        //    Cell c2 = r.CreateCell(2);
        //    c.SetCellValue(new HSSFRichTextString("\u20ac"));

        //    Cell c3 = r.CreateCell(3);
        //    String formulaString = "TEXT(12.34,\"\u20ac###,##\")";
        //    c3.CellFormula = (formulaString);


        //    string path = NPOI.Util.TempFile.GetTempFilePath("unicode", "Test.xls");
        //    FileStream tempFile = File.Create(path);
        //    wb.Write(tempFile);
        //    wb = null;
        //    tempFile.Close();
        //    FileStream in1 = new FileStream(path,FileMode.Open);
        //    wb = new HSSFWorkbook(in1);

        //    //Test the sheetname
        //    s = wb.GetSheet("\u20ac");
        //    Assert.IsNotNull(s);

        //    //Test the header
        //    h = s.Header;
        //    Assert.AreEqual(h.Center, "\u20ac");
        //    Assert.AreEqual(h.Left, "\u20ac");
        //    Assert.AreEqual(h.Right, "\u20ac");

        //    //Test the footer
        //    f = s.Footer;
        //    Assert.AreEqual(f.Center, "\u20ac");
        //    Assert.AreEqual(f.Left, "\u20ac");
        //    Assert.AreEqual(f.Right, "\u20ac");

        //    //Test the dataformat
        //    r = s.GetRow(0);
        //    c = r.GetCell(1);
        //    df = wb.CreateDataFormat();
        //    Assert.AreEqual(formatStr, df.GetFormat(c.CellStyle.DataFormat));

        //    //Test the cell string value
        //    c2 = r.GetCell(2);
        //    Assert.AreEqual(c.RichStringCellValue.String, "\u20ac");

        //    //Test the cell formula
        //    c3 = r.GetCell(3);
        //    Assert.AreEqual(c3.CellFormula, formulaString);
        //}

        /** Tests Bug38230
         *  That a Umlat is written  and then read back.
         *  It should have been written as a compressed unicode.
         * 
         * 
         *
         */
        [TestMethod]
        public void TestUmlatReadWrite()
        {
            HSSFWorkbook wb = new HSSFWorkbook();

            //Create a unicode sheet name (euro symbol)
            NPOI.SS.UserModel.Sheet s = wb.CreateSheet("Test");

            Row r = s.CreateRow(0);
            Cell c = r.CreateCell(1);
            c.SetCellValue(new HSSFRichTextString("\u00e4"));

            //Confirm that the sring will be compressed
            Assert.AreEqual(((HSSFRichTextString)c.RichStringCellValue).UnicodeString.OptionFlags, 0);

            string path = NPOI.Util.TempFile.GetTempFilePath("umlat", "Test.xls");
            FileStream tempFile = File.Create(path);

            wb.Write(tempFile);

            tempFile.Close();
            wb = null;
 
            FileStream in1 = File.Open(path,FileMode.Open);
            wb = new HSSFWorkbook(in1);
            in1.Close();
            //Test the sheetname
            s = wb.GetSheet("Test");
            Assert.IsNotNull(s);

            c = r.GetCell(1);
            Assert.AreEqual(c.RichStringCellValue.String, "\u00e4");
        }

    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.