static void Main(string[] args) { POIFSFileSystem fs = new POIFSFileSystem(); //get the root directory DirectoryEntry dir = fs.Root; //create a entry of DocumentSummaryInformation DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation(); dsi.Company = "NPOI Team"; CustomProperties customProperties = dsi.CustomProperties; if (customProperties == null) customProperties = new CustomProperties(); customProperties.Put("测试", "value A"); customProperties.Put("BB", "value BB"); customProperties.Put("CCC", "value CCC"); dsi.CustomProperties = customProperties; //Write the stream data of the DocumentSummaryInformation entry to the root directory dsi.Write(dir, DocumentSummaryInformation.DEFAULT_STREAM_NAME); //create a POIFS file called Foo.poifs FileStream output = new FileStream("Foo.xls", FileMode.OpenOrCreate); fs.WriteFileSystem(output); output.Close(); }
static void Main(string[] args) { // POI apparently can't create a document from scratch, // so we need an existing empty dummy document POIFSFileSystem fs = new POIFSFileSystem(File.OpenRead("empty.doc")); HWPFDocument doc = new HWPFDocument(fs); // centered paragraph with large font size Range range = doc.GetRange(); CharacterRun run1 = range.InsertAfter("one"); //par1.SetSpacingAfter(200); //par1.SetJustification((byte)1); // justification: 0=left, 1=center, 2=right, 3=left and right //CharacterRun run1 = par1.InsertAfter("one"); run1.SetFontSize(2 * 18); // font size: twice the point size // paragraph with bold typeface Paragraph par2 = run1.InsertAfter(new ParagraphProperties(), 0); par2.SetSpacingAfter(200); CharacterRun run2 = par2.InsertAfter("two two two two two two two two two two two two two"); run2.SetBold(true); // paragraph with italic typeface and a line indent in the first line Paragraph par3 = run2.InsertAfter(new ParagraphProperties(), 0); par3.SetFirstLineIndent(200); par3.SetSpacingAfter(200); CharacterRun run3 = par3.InsertAfter("three three three three three three three three three " + "three three three three three three three three three three three three three three " + "three three three three three three three three three three three three three three"); run3.SetItalic(true); // add a custom document property (needs POI 3.5; POI 3.2 doesn't save custom properties) DocumentSummaryInformation dsi = doc.DocumentSummaryInformation; CustomProperties cp = dsi.CustomProperties; if (cp == null) cp = new CustomProperties(); cp.Put("myProperty", "foo bar baz"); doc.Write(File.OpenWrite("new-hwpf-file.doc")); }
public void TestCustomerProperties() { String KEY = "Schlüssel "; String VALUE_1 = "Wert 1"; String VALUE_2 = "Wert 2"; CustomProperty cp; CustomProperties cps = new CustomProperties(); Assert.AreEqual(0, cps.Count); /* After Adding a custom property the size must be 1 and it must be * possible to extract the custom property from the map. */ cps.Put(KEY, VALUE_1); Assert.AreEqual(1, cps.Count); Object v1 = cps[KEY]; Assert.AreEqual(VALUE_1, v1); /* After Adding a custom property with the same name the size must still * be one. */ cps.Put(KEY, VALUE_2); Assert.AreEqual(1, cps.Count); Object v2 = cps[KEY]; Assert.AreEqual(VALUE_2, v2); /* Removing the custom property must return the Remove property and * reduce the size to 0. */ cp = (CustomProperty)cps.Remove(KEY); Assert.AreEqual(KEY, cp.Name); Assert.AreEqual(VALUE_2, cp.Value); Assert.AreEqual(0, cps.Count); }
public void TestWriteWellKnown1() { POIDataSamples _samples = POIDataSamples.GetHPSFInstance(); using (FileStream doc1 = _samples.GetFile(POI_FS)) { /* Read a Test document <em>doc1</em> into a POI filesystem. */ POIFSFileSystem poifs = new POIFSFileSystem(doc1); DirectoryEntry dir = poifs.Root; DocumentEntry siEntry = (DocumentEntry)dir.GetEntry(SummaryInformation.DEFAULT_STREAM_NAME); DocumentEntry dsiEntry = (DocumentEntry)dir.GetEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); /* * Read the summary information stream and the document summary * information stream from the POI filesystem. * * Please note that the result consists of SummaryInformation and * DocumentSummaryInformation instances which are in memory only. To * make them permanent they have to be written to a POI filesystem * explicitly (overwriting the former contents). Then the POI filesystem * should be saved to a file. */ DocumentInputStream dis = new DocumentInputStream(siEntry); PropertySet ps = new PropertySet(dis); SummaryInformation si = new SummaryInformation(ps); dis = new DocumentInputStream(dsiEntry); ps = new PropertySet(dis); DocumentSummaryInformation dsi = new DocumentSummaryInformation(ps); /* * Write all properties supported by HPSF to the summary information * (e.g. author, edit date, application name) and to the document * summary information (e.g. company, manager). */ Calendar cal = new GregorianCalendar(); //long time1 = (long)cal.GetMilliseconds(new DateTime(2000, 6, 6, 6, 6, 6)); //long time2 = (long)cal.GetMilliseconds(new DateTime(2001, 7, 7, 7, 7, 7)); //long time3 = (long)cal.GetMilliseconds(new DateTime(2002, 8, 8, 8, 8, 8)); int nr = 4711; String P_APPLICATION_NAME = "Microsoft Office Word"; String P_AUTHOR = "Rainer Klute"; int P_CHAR_COUNT = 125; String P_COMMENTS = ""; //"Comments"; DateTime P_CREATE_DATE_TIME = new DateTime(2006, 2, 1, 7, 36, 0); long P_EDIT_TIME = ++nr * 1000 * 10; String P_KEYWORDS = "Test HPSF SummaryInformation DocumentSummaryInformation Writing"; String P_LAST_AUTHOR = "LastAuthor"; DateTime? P_LAST_PRINTED = null; DateTime P_LAST_SAVE_DATE_TIME = new DateTime(2008, 9, 30, 9, 54, 0); int P_PAGE_COUNT = 1; String P_REV_NUMBER = "RevNumber"; int P_SECURITY = 1; String P_SUBJECT = "Subject"; String P_TEMPLATE = "Normal.dotm"; // FIXME (byte array properties not yet implemented): byte[] P_THUMBNAIL = new byte[123]; String P_TITLE = "This document is used for testing POI HPSF¡¯s writing capabilities for the summary information stream and the document summary information stream"; int P_WORD_COUNT = 21; int P_BYTE_COUNT = ++nr; String P_CATEGORY = "Category"; String P_COMPANY = "Rainer Klute IT-Consulting GmbH"; // FIXME (byte array properties not yet implemented): byte[] P_DOCPARTS = new byte[123]; // FIXME (byte array properties not yet implemented): byte[] P_HEADING_PAIR = new byte[123]; int P_HIDDEN_COUNT = ++nr; int P_LINE_COUNT = ++nr; bool P_LINKS_DIRTY = true; String P_MANAGER = "Manager"; int P_MM_CLIP_COUNT = ++nr; int P_NOTE_COUNT = ++nr; int P_PAR_COUNT = ++nr; String P_PRESENTATION_FORMAT = "PresentationFormat"; bool P_SCALE = false; int P_SLIDE_COUNT = ++nr; DateTime now = DateTime.Now; int POSITIVE_INTEGER = 2222; long POSITIVE_LONG = 3333; Double POSITIVE_DOUBLE = 4444; int NEGATIVE_INTEGER = 2222; long NEGATIVE_LONG = 3333; Double NEGATIVE_DOUBLE = 4444; int MAX_INTEGER = int.MaxValue; int MIN_INTEGER = int.MinValue; long MAX_LONG = long.MaxValue; long MIN_LONG = long.MinValue; Double MAX_DOUBLE = Double.MaxValue; Double MIN_DOUBLE = Double.MinValue; si.ApplicationName = P_APPLICATION_NAME; si.Author = P_AUTHOR; si.CharCount = P_CHAR_COUNT; si.Comments = P_COMMENTS; si.CreateDateTime = P_CREATE_DATE_TIME; si.EditTime = P_EDIT_TIME; si.Keywords = P_KEYWORDS; si.LastAuthor = P_LAST_AUTHOR; si.LastPrinted = P_LAST_PRINTED; si.LastSaveDateTime = P_LAST_SAVE_DATE_TIME; si.PageCount = P_PAGE_COUNT; si.RevNumber = P_REV_NUMBER; si.Security = P_SECURITY; si.Subject = P_SUBJECT; si.Template = P_TEMPLATE; // FIXME (byte array properties not yet implemented): si.Thumbnail=P_THUMBNAIL; si.Title = P_TITLE; si.WordCount = P_WORD_COUNT; dsi.ByteCount = P_BYTE_COUNT; dsi.Category = P_CATEGORY; dsi.Company = P_COMPANY; // FIXME (byte array properties not yet implemented): dsi.Docparts=P_DOCPARTS; // FIXME (byte array properties not yet implemented): dsi.HeadingPair=P_HEADING_PAIR; dsi.HiddenCount = P_HIDDEN_COUNT; dsi.LineCount = P_LINE_COUNT; dsi.LinksDirty = P_LINKS_DIRTY; dsi.Manager = P_MANAGER; dsi.MMClipCount = P_MM_CLIP_COUNT; dsi.NoteCount = P_NOTE_COUNT; dsi.ParCount = P_PAR_COUNT; dsi.PresentationFormat = P_PRESENTATION_FORMAT; dsi.Scale = P_SCALE; dsi.SlideCount = P_SLIDE_COUNT; CustomProperties customProperties = dsi.CustomProperties; if (customProperties == null) customProperties = new CustomProperties(); customProperties.Put("Schlüssel 1", "Wert 1"); customProperties.Put("Schlüssel 2", "Wert 2"); customProperties.Put("Schlüssel 3", "Wert 3"); customProperties.Put("Schlüssel 4", "Wert 4"); customProperties.Put("positive_int", POSITIVE_INTEGER); customProperties.Put("positive_long", POSITIVE_LONG); customProperties.Put("positive_Double", POSITIVE_DOUBLE); customProperties.Put("negative_int", NEGATIVE_INTEGER); customProperties.Put("negative_long", NEGATIVE_LONG); customProperties.Put("negative_Double", NEGATIVE_DOUBLE); customProperties.Put("Boolean", true); customProperties.Put("Date", now); customProperties.Put("max_int", MAX_INTEGER); customProperties.Put("min_int", MIN_INTEGER); customProperties.Put("max_long", MAX_LONG); customProperties.Put("min_long", MIN_LONG); customProperties.Put("max_Double", MAX_DOUBLE); customProperties.Put("min_Double", MIN_DOUBLE); dsi.CustomProperties = customProperties; /* Write the summary information stream and the document summary * information stream to the POI filesystem. */ si.Write(dir, siEntry.Name); dsi.Write(dir, dsiEntry.Name); /* Write the POI filesystem to a (temporary) file <em>doc2</em> * and Close the latter. */ using (FileStream doc2 = File.Create( @"\POI_HPSF_Test2.tmp")) { poifs.WriteFileSystem(doc2); //doc2.Flush(); /* * Open <em>doc2</em> for Reading and check summary information and * document summary information. All properties written before must be * found in the property streams of <em>doc2</em> and have the correct * values. */ doc2.Flush(); doc2.Position = 0; POIFSFileSystem poifs2 = new POIFSFileSystem(doc2); dir = poifs2.Root; siEntry = (DocumentEntry)dir.GetEntry(SummaryInformation.DEFAULT_STREAM_NAME); dsiEntry = (DocumentEntry)dir.GetEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); dis = new DocumentInputStream(siEntry); ps = new PropertySet(dis); si = new SummaryInformation(ps); dis = new DocumentInputStream(dsiEntry); ps = new PropertySet(dis); dsi = new DocumentSummaryInformation(ps); Assert.AreEqual(P_APPLICATION_NAME, si.ApplicationName); Assert.AreEqual(P_AUTHOR, si.Author); Assert.AreEqual(P_CHAR_COUNT, si.CharCount); Assert.AreEqual(P_COMMENTS, si.Comments); Assert.AreEqual(P_CREATE_DATE_TIME, si.CreateDateTime); Assert.AreEqual(P_EDIT_TIME, si.EditTime); Assert.AreEqual(P_KEYWORDS, si.Keywords); Assert.AreEqual(P_LAST_AUTHOR, si.LastAuthor); Assert.AreEqual(P_LAST_PRINTED, si.LastPrinted); Assert.AreEqual(P_LAST_SAVE_DATE_TIME, si.LastSaveDateTime); Assert.AreEqual(P_PAGE_COUNT, si.PageCount); Assert.AreEqual(P_REV_NUMBER, si.RevNumber); Assert.AreEqual(P_SECURITY, si.Security); Assert.AreEqual(P_SUBJECT, si.Subject); Assert.AreEqual(P_TEMPLATE, si.Template); // FIXME (byte array properties not yet implemented): Assert.AreEqual(P_THUMBNAIL, si.Thumbnail); Assert.AreEqual(P_TITLE, si.Title); Assert.AreEqual(P_WORD_COUNT, si.WordCount); Assert.AreEqual(P_BYTE_COUNT, dsi.ByteCount); Assert.AreEqual(P_CATEGORY, dsi.Category); Assert.AreEqual(P_COMPANY, dsi.Company); // FIXME (byte array properties not yet implemented): Assert.AreEqual(P_, dsi.Docparts); // FIXME (byte array properties not yet implemented): Assert.AreEqual(P_, dsi.HeadingPair); Assert.AreEqual(P_HIDDEN_COUNT, dsi.HiddenCount); Assert.AreEqual(P_LINE_COUNT, dsi.LineCount); Assert.AreEqual(P_LINKS_DIRTY, dsi.LinksDirty); Assert.AreEqual(P_MANAGER, dsi.Manager); Assert.AreEqual(P_MM_CLIP_COUNT, dsi.MMClipCount); Assert.AreEqual(P_NOTE_COUNT, dsi.NoteCount); Assert.AreEqual(P_PAR_COUNT, dsi.ParCount); Assert.AreEqual(P_PRESENTATION_FORMAT, dsi.PresentationFormat); Assert.AreEqual(P_SCALE, dsi.Scale); Assert.AreEqual(P_SLIDE_COUNT, dsi.SlideCount); CustomProperties cps = dsi.CustomProperties; //Assert.AreEqual(customProperties, cps); Assert.IsNull(cps["No value available"]); Assert.AreEqual("Wert 1", cps["Schlüssel 1"]); Assert.AreEqual("Wert 2", cps["Schlüssel 2"]); Assert.AreEqual("Wert 3", cps["Schlüssel 3"]); Assert.AreEqual("Wert 4", cps["Schlüssel 4"]); Assert.AreEqual(POSITIVE_INTEGER, cps["positive_int"]); Assert.AreEqual(POSITIVE_LONG, cps["positive_long"]); Assert.AreEqual(POSITIVE_DOUBLE, cps["positive_Double"]); Assert.AreEqual(NEGATIVE_INTEGER, cps["negative_int"]); Assert.AreEqual(NEGATIVE_LONG, cps["negative_long"]); Assert.AreEqual(NEGATIVE_DOUBLE, cps["negative_Double"]); Assert.AreEqual(true, cps["Boolean"]); Assert.AreEqual(now, cps["Date"]); Assert.AreEqual(MAX_INTEGER, cps["max_int"]); Assert.AreEqual(MIN_INTEGER, cps["min_int"]); Assert.AreEqual(MAX_LONG, cps["max_long"]); Assert.AreEqual(MIN_LONG, cps["min_long"]); Assert.AreEqual(MAX_DOUBLE, cps["max_Double"]); Assert.AreEqual(MIN_DOUBLE, cps["min_Double"]); /* Remove all properties supported by HPSF from the summary * information (e.g. author, edit date, application name) and from the * document summary information (e.g. company, manager). */ si.RemoveApplicationName(); si.RemoveAuthor(); si.RemoveCharCount(); si.RemoveComments(); si.RemoveCreateDateTime(); si.RemoveEditTime(); si.RemoveKeywords(); si.RemoveLastAuthor(); si.RemoveLastPrinted(); si.RemoveLastSaveDateTime(); si.RemovePageCount(); si.RemoveRevNumber(); si.RemoveSecurity(); si.RemoveSubject(); si.RemoveTemplate(); si.RemoveThumbnail(); si.RemoveTitle(); si.RemoveWordCount(); dsi.RemoveByteCount(); dsi.RemoveCategory(); dsi.RemoveCompany(); dsi.RemoveCustomProperties(); dsi.RemoveDocparts(); dsi.RemoveHeadingPair(); dsi.RemoveHiddenCount(); dsi.RemoveLineCount(); dsi.RemoveLinksDirty(); dsi.RemoveManager(); dsi.RemoveMMClipCount(); dsi.RemoveNoteCount(); dsi.RemoveParCount(); dsi.RemovePresentationFormat(); dsi.RemoveScale(); dsi.RemoveSlideCount(); /* * <li>Write the summary information stream and the document summary * information stream to the POI filesystem. */ si.Write(dir, siEntry.Name); dsi.Write(dir, dsiEntry.Name); /* * <li>Write the POI filesystem to a (temporary) file <em>doc3</em> * and Close the latter. */ using (FileStream doc3 = File.Create( @"\POI_HPSF_Test3.tmp")) { poifs2.WriteFileSystem(doc3); doc3.Position = 0; /* * Open <em>doc3</em> for Reading and check summary information * and document summary information. All properties Removed before must not * be found in the property streams of <em>doc3</em>. */ POIFSFileSystem poifs3 = new POIFSFileSystem(doc3); dir = poifs3.Root; siEntry = (DocumentEntry)dir.GetEntry(SummaryInformation.DEFAULT_STREAM_NAME); dsiEntry = (DocumentEntry)dir.GetEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); dis = new DocumentInputStream(siEntry); ps = new PropertySet(dis); si = new SummaryInformation(ps); dis = new DocumentInputStream(dsiEntry); ps = new PropertySet(dis); dsi = new DocumentSummaryInformation(ps); Assert.AreEqual(null, si.ApplicationName); Assert.AreEqual(null, si.Author); Assert.AreEqual(0, si.CharCount); Assert.IsTrue(si.WasNull); Assert.AreEqual(null, si.Comments); Assert.AreEqual(null, si.CreateDateTime); Assert.AreEqual(0, si.EditTime); Assert.IsTrue(si.WasNull); Assert.AreEqual(null, si.Keywords); Assert.AreEqual(null, si.LastAuthor); Assert.AreEqual(null, si.LastPrinted); Assert.AreEqual(null, si.LastSaveDateTime); Assert.AreEqual(0, si.PageCount); Assert.IsTrue(si.WasNull); Assert.AreEqual(null, si.RevNumber); Assert.AreEqual(0, si.Security); Assert.IsTrue(si.WasNull); Assert.AreEqual(null, si.Subject); Assert.AreEqual(null, si.Template); Assert.AreEqual(null, si.Thumbnail); Assert.AreEqual(null, si.Title); Assert.AreEqual(0, si.WordCount); Assert.IsTrue(si.WasNull); Assert.AreEqual(0, dsi.ByteCount); Assert.IsTrue(dsi.WasNull); Assert.AreEqual(null, dsi.Category); Assert.AreEqual(null, dsi.CustomProperties); // FIXME (byte array properties not yet implemented): Assert.AreEqual(null, dsi.Docparts); // FIXME (byte array properties not yet implemented): Assert.AreEqual(null, dsi.HeadingPair); Assert.AreEqual(0, dsi.HiddenCount); Assert.IsTrue(dsi.WasNull); Assert.AreEqual(0, dsi.LineCount); Assert.IsTrue(dsi.WasNull); Assert.AreEqual(false, dsi.LinksDirty); Assert.IsTrue(dsi.WasNull); Assert.AreEqual(null, dsi.Manager); Assert.AreEqual(0, dsi.MMClipCount); Assert.IsTrue(dsi.WasNull); Assert.AreEqual(0, dsi.NoteCount); Assert.IsTrue(dsi.WasNull); Assert.AreEqual(0, dsi.ParCount); Assert.IsTrue(dsi.WasNull); Assert.AreEqual(null, dsi.PresentationFormat); Assert.AreEqual(false, dsi.Scale); Assert.IsTrue(dsi.WasNull); Assert.AreEqual(0, dsi.SlideCount); Assert.IsTrue(dsi.WasNull); } } } File.Delete( @"\POI_HPSF_Test3.tmp"); File.Delete( @"\POI_HPSF_Test2.tmp"); }
public void TestConvAndExistance() { CustomProperties customProperties = dsi.CustomProperties; if (customProperties == null) { customProperties = new CustomProperties(); } /* Insert some custom properties into the container. */ customProperties.Put("int", 12345); customProperties.Put("negint", -12345); customProperties.Put("long", (long)12345); customProperties.Put("neglong", (long)-12345); customProperties.Put("bool", true); customProperties.Put("string", "a String"); //customProperties.Put("float", new Float(12345.0))); is not valid //customProperties.Put("negfloat", new Float(-12345.1))); is not valid customProperties.Put("double", (double)12345.2); customProperties.Put("negdouble", (double)-12345.3); //customProperties.Put("char", new Character('a'))); is not valid DateTime date = new DateTime(1984, 5, 16, 8, 23, 15); customProperties.Put("date", date); dsi.CustomProperties = customProperties; CloseAndReOpen(); Assert.IsNotNull(dsi); Assert.IsNotNull(si); /* Change the category to "POI example". Any former category value will * be lost. If there has been no category yet, it will be Created. */ Assert.IsNull(dsi.Category); Assert.IsNull(dsi.Company); Assert.IsNull(dsi.Manager); Assert.IsNull(si.Author); Assert.IsNull(si.Title); Assert.IsNull(si.Comments); Assert.IsNull(si.Keywords); Assert.IsNull(si.Subject); /* Read the custom properties. If there are no custom properties * yet, the application has to Create a new CustomProperties object. * It will serve as a container for custom properties. */ customProperties = dsi.CustomProperties; if (customProperties == null) { Assert.Fail(); } /* Insert some custom properties into the container. */ int a3 = (int)customProperties["int"]; Assert.AreEqual(12345, a3, "int"); a3 = (int)customProperties["negint"]; Assert.AreEqual(-12345, a3, "negint"); long al = (long)customProperties["neglong"]; Assert.AreEqual(-12345, al, "neglong"); al = (long)customProperties["long"]; Assert.AreEqual(12345, al, "long"); Boolean a4 = (Boolean)customProperties["bool"]; Assert.AreEqual(true, a4, "bool"); DateTime a5 = (DateTime)customProperties["date"]; Assert.AreEqual(date, a5, "Custom Date:"); Double d = (Double)customProperties["double"]; Assert.AreEqual(12345.2, d, "int"); d = (Double)customProperties["negdouble"]; Assert.AreEqual(-12345.3, d, "string"); String s = (String)customProperties["string"]; Assert.AreEqual("a String", s, "sring"); Object o = null; o = customProperties["string"]; if (!(o is String)) { Assert.Fail(); } o = customProperties["bool"]; if (!(o is Boolean)) { Assert.Fail(); } o = customProperties["int"]; if (!(o is int)) { Assert.Fail(); } o = customProperties["negint"]; if (!(o is int)) { Assert.Fail(); } o = customProperties["long"]; if (!(o is long)) { Assert.Fail(); } o = customProperties["neglong"]; if (!(o is long)) { Assert.Fail(); } o = customProperties["double"]; if (!(o is Double)) { Assert.Fail(); } o = customProperties["negdouble"]; if (!(o is Double)) { Assert.Fail(); } o = customProperties["date"]; if (!(o is DateTime)) { Assert.Fail(); } }
public void TestUnicode() { String company = StrangizeU("company"); String manager = StrangizeU("manager"); String category = StrangizeU("category"); String title = StrangizeU("title"); String author = StrangizeU("author"); String comments = StrangizeU("comments"); String keywords = StrangizeU("keywords"); String subject = StrangizeU("subject"); String p1 = StrangizeU("p1"); String p2 = StrangizeU("p2"); String k1 = StrangizeU("k1"); String k2 = StrangizeU("k2"); dsi.Company = company; dsi.Manager = manager; dsi.Category = category; si.Title = title; si.Author = author; si.Comments = comments; si.Keywords = keywords; si.Subject = subject; CustomProperties customProperties = dsi.CustomProperties; if (customProperties == null) { customProperties = new CustomProperties(); } /* Insert some custom properties into the container. */ customProperties.Put(k1, p1); customProperties.Put(k2, p2); customProperties.Put("Sample Number", 12345); customProperties.Put("Sample Boolean", true); DateTime date = new DateTime(1984, 5, 16, 8, 23, 15); customProperties.Put("Sample Date", date); dsi.CustomProperties = customProperties; CloseAndReOpen(); Assert.IsNotNull(dsi); Assert.IsNotNull(si); /* Change the category to "POI example". Any former category value will * be lost. If there has been no category yet, it will be Created. */ Assert.AreEqual(category, dsi.Category, "Category"); Assert.AreEqual(company, dsi.Company, "Company"); Assert.AreEqual(manager, dsi.Manager, "Manager"); Assert.AreEqual(author, si.Author, ""); Assert.AreEqual(title, si.Title, ""); Assert.AreEqual(comments, si.Comments, ""); Assert.AreEqual(keywords, si.Keywords, ""); Assert.AreEqual(subject, si.Subject, ""); /* Read the custom properties. If there are no custom properties yet, * the application has to Create a new CustomProperties object. It will * serve as a container for custom properties. */ customProperties = dsi.CustomProperties; if (customProperties == null) { Assert.Fail(); } /* Insert some custom properties into the container. */ // System.out.println(k1); String a1 = (String)customProperties[k1]; Assert.AreEqual(p1, a1, "Key1"); String a2 = (String)customProperties[k2]; Assert.AreEqual(p2, a2, "Schlüsel2"); int a3 = (int)customProperties["Sample Number"]; Assert.AreEqual(12345, a3, "Sample Number"); Boolean a4 = (Boolean)customProperties["Sample Boolean"]; Assert.AreEqual(true, a4, "Sample Boolean"); DateTime a5 = (DateTime)customProperties["Sample Date"]; Assert.AreEqual(date, a5, "Custom Date:"); }
public void TestOne() { //DocumentSummaryInformation dsi.Company = "xxxCompanyxxx"; dsi.Manager = "xxxManagerxxx"; dsi.Category = "xxxCategoryxxx"; //SummaryInformation si.Title = "xxxTitlexxx"; si.Author = "xxxAuthorxxx"; si.Comments = "xxxCommentsxxx"; si.Keywords = "xxxKeyWordsxxx"; si.Subject = "xxxSubjectxxx"; //Custom Properties (in DocumentSummaryInformation CustomProperties customProperties = dsi.CustomProperties; if (customProperties == null) { customProperties = new CustomProperties(); } /* Insert some custom properties into the container. */ customProperties.Put("Key1","Value1"); customProperties.Put("Schlüsel2", "Wert2"); customProperties.Put("Sample Integer", 12345); customProperties.Put("Sample Boolean", true); DateTime date = new DateTime(1988,1,5,5,34,12); customProperties.Put("Sample Date", date); customProperties.Put("Sample Double", -1.0001); customProperties.Put("Sample Negative Integer", -100000); dsi.CustomProperties = customProperties; //start Reading CloseAndReOpen(); //Testing Assert.IsNotNull(dsi); Assert.IsNotNull(si); Assert.AreEqual("xxxCategoryxxx", dsi.Category, "Category"); Assert.AreEqual("xxxCompanyxxx", dsi.Company, "Company"); Assert.AreEqual("xxxManagerxxx", dsi.Manager, "Manager"); Assert.AreEqual( "xxxAuthorxxx", si.Author); Assert.AreEqual("xxxTitlexxx", si.Title); Assert.AreEqual("xxxCommentsxxx", si.Comments); Assert.AreEqual("xxxKeyWordsxxx", si.Keywords); Assert.AreEqual("xxxSubjectxxx", si.Subject); /* Read the custom properties. If there are no custom properties yet, * the application has to Create a new CustomProperties object. It will * serve as a container for custom properties. */ customProperties = dsi.CustomProperties; if (customProperties == null) { Assert.Fail(); } /* Insert some custom properties into the container. */ String a1 = (String)customProperties["Key1"]; Assert.AreEqual("Value1", a1, "Key1"); String a2 = (String)customProperties["Schlüsel2"]; Assert.AreEqual("Wert2", a2, "Schlüsel2"); int a3 = (int)customProperties["Sample Integer"]; Assert.AreEqual(12345, a3, "Sample Number"); Boolean a4 = (Boolean)customProperties["Sample Boolean"]; Assert.AreEqual(true, a4, "Sample Boolean"); DateTime a5 = (DateTime)customProperties["Sample Date"]; Assert.AreEqual(date, a5, "Custom Date:"); Double a6 = (Double)customProperties["Sample Double"]; Assert.AreEqual(-1.0001, a6, "Custom Float"); int a7 = (int)customProperties["Sample Negative Integer"]; Assert.AreEqual(-100000, a7, "Neg"); }