public void CloseDoesNotModifyWorkbook() { String filename = "SampleSS.xlsx"; FileInfo file = POIDataSamples.GetSpreadSheetInstance().GetFileInfo(filename); IWorkbook wb; // Some tests commented out because close() modifies the file // See bug 58779 // String //wb = new XSSFWorkbook(file.Path); //assertCloseDoesNotModifyFile(filename, wb); // File //wb = new XSSFWorkbook(file); //assertCloseDoesNotModifyFile(filename, wb); // InputStream wb = new XSSFWorkbook(file.OpenRead()); assertCloseDoesNotModifyFile(filename, wb); // OPCPackage //wb = new XSSFWorkbook(OPCPackage.open(file)); //assertCloseDoesNotModifyFile(filename, wb); }
public void TestPropertySetMethods() { POIDataSamples samples = POIDataSamples.GetHPSFInstance(); using (FileStream data = samples.GetFile(POI_FS)) { POIFile poiFile = Util.ReadPOIFiles(data, POI_FILES)[0]; byte[] b = poiFile.GetBytes(); PropertySet ps = PropertySetFactory.Create(new ByteArrayInputStream(b)); Assert.IsTrue(ps.IsDocumentSummaryInformation, "IsDocumentSummaryInformation"); Assert.AreEqual(ps.SectionCount, 2); Section s = (Section)ps.Sections[1]; Assert.AreEqual(s.GetProperty(1), CodePageUtil.CP_UTF16); Assert.AreEqual(s.GetProperty(2), -96070278); Assert.AreEqual(s.GetProperty(3), "MCon_Info zu Office bei Schreiner"); Assert.AreEqual(s.GetProperty(4), "*****@*****.**"); Assert.AreEqual(s.GetProperty(5), "Petrovitsch, Wilhelm"); } }
public static byte[] GetImage(String filename) { Stream is1 = POIDataSamples.GetDocumentInstance().OpenResourceAsStream(filename); byte[] result = IOUtils.ToByteArray(is1); return(result); }
public void Bug57080() { // the test file Contains a wrong ole entry size, produced by extenxls // the fix limits the available size and tries to read all entries FileStream f = POIDataSamples.GetPOIFSInstance().GetFile("extenxls_pwd123.xlsx"); NPOIFSFileSystem fs = new NPOIFSFileSystem(f, true); EncryptionInfo info = new EncryptionInfo(fs); Decryptor d = Decryptor.GetInstance(info); d.VerifyPassword("pwd123"); MemoryStream bos = new MemoryStream(); ZipInputStream zis = new ZipInputStream(d.GetDataStream(fs)); ZipEntry ze; while ((ze = zis.GetNextEntry()) != null) { //bos.Reset(); bos.Seek(0, SeekOrigin.Begin); bos.SetLength(0); IOUtils.Copy(zis, bos); Assert.AreEqual(ze.Size, bos.Length); } zis.Close(); fs.Close(); }
protected static String ReadVBA(POIDataSamples poiDataSamples) { FileInfo macro = poiDataSamples.GetFileInfo("SimpleMacro.vba"); byte[] bytes; try { FileStream stream = new FileStream(macro.FullName, FileMode.Open, FileAccess.ReadWrite); try { bytes = IOUtils.ToByteArray(stream); } finally { stream.Close(); } } catch (IOException e) { //throw new Exception(e); throw e; } String testMacroContents = Encoding.UTF8.GetString(bytes); if (!testMacroContents.StartsWith("Sub ")) { throw new ArgumentException("Not a macro"); } return(testMacroContents.Substring(testMacroContents.IndexOf("()") + 3)); }
public void TestReadCustomPropertiesFromFiles() { POIDataSamples _samples = POIDataSamples.GetHPSFInstance(); string[] files = _samples.GetFiles("Test*.*"); for (int i = 0; i < files.Length; i++) { if (TestReadAllFiles.checkExclude(files[i])) { continue; } using (FileStream file = new FileStream(files[i], FileMode.Open, FileAccess.Read)) { try { RunTest(file); } catch (Exception e) { throw new IOException("While handling file " + files[i], e); } } } }
public void TestReadAllFiles1() { //string dataDir = @"..\..\..\TestCases\HPSF\data\"; POIDataSamples _samples = POIDataSamples.GetHPSFInstance(); string[] files = _samples.GetFiles(); try { for (int i = 0; i < files.Length; i++) { if (files[i].EndsWith("1")) { continue; } FileStream f = new FileStream(files[i], FileMode.Open, FileAccess.Read); /* Read the POI filesystem's property Set streams: */ POIFile[] psf1 = Util.ReadPropertySets(f); for (int j = 0; j < psf1.Length; j++) { Stream in1 = new MemoryStream(psf1[j].GetBytes()); PropertySet a = PropertySetFactory.Create(in1); } f.Close(); } } catch (Exception t) { String s = t.ToString(); Assert.Fail(s); } }
/** * Constructor * * @param name The name of the Test case */ public TestEmptyProperties() { POIDataSamples samples = POIDataSamples.GetHPSFInstance(); Stream data = samples.OpenResourceAsStream(POI_FS);; poiFiles = Util.ReadPOIFiles(data); }
/** * Test case constructor. * * @param name The Test case's name. */ public TestBasic() { //FileStream data =File.OpenRead(dataDir+POI_FS); POIDataSamples samples = POIDataSamples.GetHPSFInstance(); Stream data = (Stream)samples.OpenResourceAsStream(POI_FS); poiFiles = Util.ReadPOIFiles(data); }
public void TestDOCX() { POIDataSamples pds = POIDataSamples.GetDocumentInstance(); AssertReadWrite( PackageHelper.Open(pds.OpenResourceAsStream("WordWithAttachments.docx")) ); }
public void TestXLSX() { POIDataSamples pds = POIDataSamples.GetSpreadSheetInstance(); AssertReadWrite( PackageHelper.Open(pds.OpenResourceAsStream("ExcelWithAttachments.xlsm")) ); }
public void TestPPTX() { POIDataSamples pds = POIDataSamples.GetSlideShowInstance(); AssertReadWrite( PackageHelper.Open(pds.OpenResourceAsStream("PPTWithAttachments.pptm")) ); }
public void TestWord() { POIXMLDocument doc = new XWPFDocument( POIDataSamples.GetDocumentInstance().OpenResourceAsStream("WordWithAttachments.docx") ); Test(doc, 5); }
public void TestExcel() { POIXMLDocument doc = new XSSFWorkbook( POIDataSamples.GetSpreadSheetInstance().OpenResourceAsStream("ExcelWithAttachments.xlsm") ); Test(doc, 4); }
public void TestReadDocumentSummaryInformation() { POIDataSamples _samples = POIDataSamples.GetHPSFInstance(); string[] files = _samples.GetFiles("Test*.*"); for (int i = 0; i < files.Length; i++) { FileStream doc = new FileStream(files[i], FileMode.Open); Console.WriteLine("Reading file " + doc); /* Read a Test document <em>doc</em> into a POI filesystem. */ POIFSFileSystem poifs = new POIFSFileSystem(doc); DirectoryEntry dir = poifs.Root; DocumentEntry dsiEntry = null; try { dsiEntry = (DocumentEntry)dir.GetEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); } catch (FileNotFoundException) { /* * A missing document summary information stream is not an error * and therefore silently ignored here. */ } /* * If there is a document summry information stream, Read it from * the POI filesystem. */ if (dsiEntry != null) { POIFSDocumentReader dis = new POIFSDocumentReader(dsiEntry); PropertySet ps = new PropertySet(dis); DocumentSummaryInformation dsi = new DocumentSummaryInformation(ps); /* Execute the Get... methods. */ Console.WriteLine(dsi.ByteCount); Console.WriteLine(dsi.ByteOrder); Console.WriteLine(dsi.Category); Console.WriteLine(dsi.Company); Console.WriteLine(dsi.CustomProperties); // FIXME Console.WriteLine(dsi.Docparts); // FIXME Console.WriteLine(dsi.HeadingPair); Console.WriteLine(dsi.HiddenCount); Console.WriteLine(dsi.LineCount); Console.WriteLine(dsi.LinksDirty); Console.WriteLine(dsi.Manager); Console.WriteLine(dsi.MMClipCount); Console.WriteLine(dsi.NoteCount); Console.WriteLine(dsi.ParCount); Console.WriteLine(dsi.PresentationFormat); Console.WriteLine(dsi.Scale); Console.WriteLine(dsi.SlideCount); } } }
static POIFSFileSystem GetSamplePPT() { // scratchpad classes are not available, so we use something pre-cooked Stream is1 = POIDataSamples.GetSlideShowInstance().OpenResourceAsStream("with_textbox.ppt"); POIFSFileSystem poifs = new POIFSFileSystem(is1); is1.Close(); return(poifs); }
public void TestFirstParagraphFix() { extractor = new WordExtractor( POIDataSamples.GetDocumentInstance().OpenResourceAsStream("Bug48075.doc") ); String text = extractor.Text; Assert.IsTrue(text.StartsWith("\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435")); }
private static String getFoText(String sampleFileName) { HWPFDocument hwpfDocument = new HWPFDocument(POIDataSamples.GetDocumentInstance().OpenResourceAsStream(sampleFileName)); WordToFoConverter wordToFoConverter = new WordToFoConverter(new XmlDocument()); wordToFoConverter.ProcessDocument(hwpfDocument); return(wordToFoConverter.Document.InnerXml); }
public void TestPasswordVerification() { POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.GetPOIFSInstance().OpenResourceAsStream("protect.xlsx")); EncryptionInfo info = new EncryptionInfo(fs); Decryptor d = Decryptor.GetInstance(info); Assert.IsTrue(d.VerifyPassword(Decryptor.DEFAULT_PASSWORD)); }
public void TestFastSaved() { extractor = new WordExtractor( POIDataSamples.GetDocumentInstance().OpenResourceAsStream("rasp.doc") ); String text = extractor.Text; Assert.IsTrue(text.Contains("\u0425\u0425\u0425\u0425\u0425")); Assert.IsTrue(text.Contains("\u0423\u0423\u0423\u0423\u0423")); }
public void TestProblemMetadata() { WordExtractor extractor = new WordExtractor(POIDataSamples.GetDocumentInstance().OpenResourceAsStream("ProblemExtracting.doc")); // Check it gives text without error string text = extractor.Text; string[] paratext = extractor.ParagraphText; string textfrompieces = extractor.TextFromPieces; }
public void TestRemoveCommentShape() { XSSFVMLDrawing vml = new XSSFVMLDrawing(); vml.Read(POIDataSamples.GetSpreadSheetInstance().OpenResourceAsStream("vmlDrawing1.vml")); CT_Shape sh_a1 = vml.FindCommentShape(0, 0); Assert.IsNotNull(sh_a1); Assert.IsTrue(vml.RemoveCommentShape(0, 0)); Assert.IsNull(vml.FindCommentShape(0, 0)); }
public void TestRelationOrder() { OPCPackage pkg = PackageHelper.Open(POIDataSamples.GetDocumentInstance().OpenResourceAsStream("WordWithAttachments.docx")); OPCParser doc = new OPCParser(pkg); doc.Parse(new TestFactory()); foreach (POIXMLDocumentPart rel in doc.GetRelations()) { //TODO finish me } }
public void TestInnerTable() { Stream resourceAsStream = POIDataSamples.GetDocumentInstance() .OpenResourceAsStream("innertable.doc"); HWPFDocument hwpfDocument = new HWPFDocument(resourceAsStream); resourceAsStream.Close(); TestInnerTable(hwpfDocument); hwpfDocument = Reload(hwpfDocument); TestInnerTable(hwpfDocument); }
public void TestDecrypt() { POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.GetPOIFSInstance().OpenResourceAsStream("protect.xlsx")); EncryptionInfo info = new EncryptionInfo(fs); Decryptor d = Decryptor.GetInstance(info); d.VerifyPassword(Decryptor.DEFAULT_PASSWORD); ZipOk(fs, d); }
public void Bug60158() { try { FromFile(POIDataSamples.GetDocumentInstance(), "60158.docm"); POITestCase.TestPassesNow(60158); } catch (IndexOutOfRangeException e) { POITestCase.SkipTest(e); } }
public void TestReadMultipleTreeLevels() { POIDataSamples _samples = POIDataSamples.GetPublisherInstance(); FileStream sample = _samples.GetFile("Sample.pub"); DocumentInputStream stream; NPOIFSFileSystem npoifs = new NPOIFSFileSystem(sample); try { sample = _samples.GetFile("Sample.pub"); OPOIFSFileSystem opoifs = new OPOIFSFileSystem(sample); // Ensure we have what we expect on the root Assert.AreEqual(npoifs, npoifs.Root.NFileSystem); Assert.AreEqual(npoifs, npoifs.Root.FileSystem); Assert.AreEqual(null, npoifs.Root.OFileSystem); Assert.AreEqual(null, opoifs.Root.FileSystem); Assert.AreEqual(opoifs, opoifs.Root.OFileSystem); Assert.AreEqual(null, opoifs.Root.NFileSystem); // Check inside foreach (DirectoryNode root in new DirectoryNode[] { opoifs.Root, npoifs.Root }) { // Top Level Entry top = root.GetEntry("Contents"); Assert.AreEqual(true, top.IsDocumentEntry); stream = root.CreateDocumentInputStream(top); stream.Read(); // One Level Down DirectoryNode escher = (DirectoryNode)root.GetEntry("Escher"); Entry one = escher.GetEntry("EscherStm"); Assert.AreEqual(true, one.IsDocumentEntry); stream = escher.CreateDocumentInputStream(one); stream.Read(); // Two Levels Down DirectoryNode quill = (DirectoryNode)root.GetEntry("Quill"); DirectoryNode quillSub = (DirectoryNode)quill.GetEntry("QuillSub"); Entry two = quillSub.GetEntry("CONTENTS"); Assert.AreEqual(true, two.IsDocumentEntry); stream = quillSub.CreateDocumentInputStream(two); stream.Read(); } } finally { npoifs.Close(); } }
private static POIFSFileSystem OpenSampleFS() { Stream is1 = POIDataSamples.GetSpreadSheetInstance().GetFile("39234.xls"); try { return(new POIFSFileSystem(is1)); } catch (IOException) { throw; } }
public void TestReadCustomPropertiesFromFiles() { POIDataSamples _samples = POIDataSamples.GetHPSFInstance(); string[] files = _samples.GetFiles("Test*.*"); for (int i = 0; i < files.Length; i++) { FileStream file = new FileStream(files[i], FileMode.Open); RunTest(file); } }
public void Bug59058() { String[] files = { "bug57031.docx", "bug59058.docx" }; foreach (String f in files) { ZipFile zf = new ZipFile(POIDataSamples.GetDocumentInstance().GetFile(f)); ZipEntry entry = zf.GetEntry("word/document.xml"); XmlDocument xml = POIXMLDocumentPart.ConvertStreamToXml(zf.GetInputStream(entry)); DocumentDocument document = DocumentDocument.Parse(xml, POIXMLDocumentPart.NamespaceManager); Assert.IsNotNull(document); zf.Close(); } }