本文整理汇总了C#中NPOI.POIFS.FileSystem.POIFSFileSystem类的典型用法代码示例。如果您正苦于以下问题:C# POIFSFileSystem类的具体用法?C# POIFSFileSystem怎么用?C# POIFSFileSystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
POIFSFileSystem类属于NPOI.POIFS.FileSystem命名空间,在下文中一共展示了POIFSFileSystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test4KBlocks
public void Test4KBlocks()
{
Stream inp = _samples.OpenResourceAsStream("BlockSize4096.zvi");
// First up, check that we can process the header properly
HeaderBlock header_block = new HeaderBlock(inp);
POIFSBigBlockSize bigBlockSize = header_block.BigBlockSize;
Assert.AreEqual(4096, bigBlockSize.GetBigBlockSize());
// Check the fat info looks sane
Assert.AreEqual(1, header_block.BATArray.Length);
Assert.AreEqual(1, header_block.BATCount);
Assert.AreEqual(0, header_block.XBATCount);
// Now check we can get the basic fat
RawDataBlockList data_blocks = new RawDataBlockList(inp, bigBlockSize);
// Now try and open properly
POIFSFileSystem fs = new POIFSFileSystem(
_samples.OpenResourceAsStream("BlockSize4096.zvi")
);
Assert.IsTrue(fs.Root.EntryCount > 3);
// Check we can get at all the contents
CheckAllDirectoryContents(fs.Root);
// Finally, check we can do a similar 512byte one too
fs = new POIFSFileSystem(
_samples.OpenResourceAsStream("BlockSize512.zvi")
);
Assert.IsTrue(fs.Root.EntryCount > 3);
CheckAllDirectoryContents(fs.Root);
}
示例2: ViewFile
public static void ViewFile(String filename)
{
POIFSFileSystem fs = new POIFSFileSystem(
new FileStream(filename, FileMode.Open)
);
DisplayDirectory(fs.Root, "");
}
示例3: TestWrite
public void TestWrite()
{
Stream is1 = HSSFTestDataSamples.OpenSampleFileStream(xlsA);
POIFSFileSystem fs = new POIFSFileSystem(is1);
// Open the workbook, not preserving nodes
HSSFWorkbook wb = new HSSFWorkbook(fs);
MemoryStream out1 = new MemoryStream();
wb.Write(out1);
// Check now
MemoryStream in1 = new MemoryStream(out1.ToArray());
POIFSFileSystem fs2 = new POIFSFileSystem(in1);
// Check that we have the new entries
fs2.Root.GetEntry("Workbook");
try
{
fs2.Root.GetEntry("WORKBOOK");
Assert.Fail();
}
catch (FileNotFoundException) { }
// And it can be Opened
HSSFWorkbook wb2 = new HSSFWorkbook(fs2);
}
示例4: TestFail
public void TestFail()
{
Stream is1 = HSSFTestDataSamples.OpenSampleFileStream("Simple.xls");
POIFSFileSystem fs = new POIFSFileSystem(is1);
HSSFWorkbook wb = new HSSFWorkbook(fs);
//set POIFS properties after constructing HSSFWorkbook
//(a piece of code that used to work up to POI 3.0.2)
SummaryInformation summary1 = (SummaryInformation)PropertySetFactory.Create(fs.CreateDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
summary1.Title=(title);
//Write the modified property back to POIFS
fs.Root.GetEntry(SummaryInformation.DEFAULT_STREAM_NAME).Delete();
fs.CreateDocument(summary1.ToStream(), SummaryInformation.DEFAULT_STREAM_NAME);
//save the workbook and read the property
MemoryStream out1 = new MemoryStream();
wb.Write(out1);
out1.Close();
POIFSFileSystem fs2 = new POIFSFileSystem(new MemoryStream(out1.ToArray()));
SummaryInformation summary2 = (SummaryInformation)PropertySetFactory.Create(fs2.CreateDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
//Assert.Failing assertion
Assert.AreEqual(title, summary2.Title);
}
示例5: TestWithCrazyContinueRecords
public void TestWithCrazyContinueRecords()
{
// Some files have crazy ordering of their continue records
// Check that we don't break on them (bug #42844)
HSSFRequest req = new HSSFRequest();
MockHSSFListener mockListen = new MockHSSFListener();
req.AddListenerForAllRecords(mockListen);
POIFSFileSystem fs = new POIFSFileSystem(OpenSample("ContinueRecordProblem.xls"));
HSSFEventFactory factory = new HSSFEventFactory();
factory.ProcessWorkbookEvents(req, fs);
Record[] recs = mockListen.GetRecords();
// Check we got the records
Assert.IsTrue(recs.Length > 100);
// And none of them are continue ones
for (int i = 0; i < recs.Length; i++)
{
Assert.IsFalse(recs[i] is ContinueRecord);
}
// Check that the last few records are as we expect
// (Makes sure we don't accidently skip the end ones)
int numRec = recs.Length;
Assert.AreEqual(typeof(DVALRecord), recs[numRec - 3].GetType());
Assert.AreEqual(typeof(DVRecord), recs[numRec - 2].GetType());
Assert.AreEqual(typeof(EOFRecord), recs[numRec - 1].GetType());
}
示例6: TestRecord
public void TestRecord()
{
POIFSFileSystem fs = new POIFSFileSystem(
HSSFTestDataSamples.OpenSampleFileStream("WithFormattedGraphTitle.xls"));
// Check we can Open the file via usermodel
HSSFWorkbook hssf = new HSSFWorkbook(fs);
// Now process it through eventusermodel, and
// look out for the title records
ChartTitleFormatRecordGrabber grabber = new ChartTitleFormatRecordGrabber();
Stream din = fs.CreateDocumentInputStream("Workbook");
HSSFRequest req = new HSSFRequest();
req.AddListenerForAllRecords(grabber);
HSSFEventFactory factory = new HSSFEventFactory();
factory.ProcessEvents(req, din);
din.Close();
// Should've found one
Assert.AreEqual(1, grabber.chartTitleFormatRecords.Count);
// And it should be of something interesting
AlRunsRecord r =
(AlRunsRecord)grabber.chartTitleFormatRecords[0];
Assert.AreEqual(3, r.GetFormatCount());
}
示例7: TestOpenBOOK
public void TestOpenBOOK()
{
Stream is1 = HSSFTestDataSamples.OpenSampleFileStream(xlsB);
POIFSFileSystem fs = new POIFSFileSystem(is1);
// Ensure that we have a BOOK entry
fs.Root.GetEntry("BOOK");
Assert.IsTrue(true);
// But not a Workbook one
try
{
fs.Root.GetEntry("Workbook");
Assert.Fail();
}
catch (FileNotFoundException) { }
// And not a Summary one
try
{
fs.Root.GetEntry("\005SummaryInformation");
Assert.Fail();
}
catch (FileNotFoundException) { }
// Try to open the workbook
HSSFWorkbook wb = new HSSFWorkbook(fs);
}
示例8: SetUp
public void SetUp()
{
POIFSFileSystem filesystem = new POIFSFileSystem(
POIDataSamples.GetDocumentInstance().OpenResourceAsStream("test.doc"));
DocumentEntry documentProps =
(DocumentEntry)filesystem.Root.GetEntry("WordDocument");
_mainStream = new byte[documentProps.Size];
filesystem.CreateDocumentInputStream("WordDocument").Read(_mainStream);
// use the fib to determine the name of the table stream.
_fib = new FileInformationBlock(_mainStream);
String name = "0Table";
if (_fib.IsFWhichTblStm())
{
name = "1Table";
}
// read in the table stream.
DocumentEntry tableProps =
(DocumentEntry)filesystem.Root.GetEntry(name);
_tableStream = new byte[tableProps.Size];
filesystem.CreateDocumentInputStream(name).Read(_tableStream);
_fib.FillVariableFields(_mainStream, _tableStream);
}
示例9: Main
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();
}
示例10: TestOleNative
public void TestOleNative()
{
POIFSFileSystem fs = new POIFSFileSystem(dataSamples.OpenResourceAsStream("oleObject1.bin"));
Ole10Native ole = Ole10Native.CreateFromEmbeddedOleObject(fs);
Assert.AreEqual("File1.svg", ole.Label);
Assert.AreEqual("D:\\Documents and Settings\\rsc\\My Documents\\file1.svg", ole.Command);
}
示例11: TestCopyRecursively
public void TestCopyRecursively()
{
POIFSFileSystem fsD = new POIFSFileSystem();
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry dirA = fs.CreateDirectory("DirA");
DirectoryEntry dirB = fs.CreateDirectory("DirB");
DocumentEntry entryR = fs.CreateDocument(new ByteArrayInputStream(dataSmallA), "EntryRoot");
DocumentEntry entryA1 = dirA.CreateDocument("EntryA1", new ByteArrayInputStream(dataSmallA));
DocumentEntry entryA2 = dirA.CreateDocument("EntryA2", new ByteArrayInputStream(dataSmallB));
// Copy docs
Assert.AreEqual(0, fsD.Root.EntryCount);
EntryUtils.CopyNodeRecursively(entryR, fsD.Root);
Assert.AreEqual(1, fsD.Root.EntryCount);
Assert.IsNotNull(fsD.Root.GetEntry("EntryRoot"));
EntryUtils.CopyNodeRecursively(entryA1, fsD.Root);
Assert.AreEqual(2, fsD.Root.EntryCount);
Assert.IsNotNull(fsD.Root.GetEntry("EntryRoot"));
Assert.IsNotNull(fsD.Root.GetEntry("EntryA1"));
EntryUtils.CopyNodeRecursively(entryA2, fsD.Root);
Assert.AreEqual(3, fsD.Root.EntryCount);
Assert.IsNotNull(fsD.Root.GetEntry("EntryRoot"));
Assert.IsNotNull(fsD.Root.GetEntry("EntryA1"));
Assert.IsNotNull(fsD.Root.GetEntry("EntryA2"));
// Copy directories
fsD = new POIFSFileSystem();
Assert.AreEqual(0, fsD.Root.EntryCount);
EntryUtils.CopyNodeRecursively(dirB, fsD.Root);
Assert.AreEqual(1, fsD.Root.EntryCount);
Assert.IsNotNull(fsD.Root.GetEntry("DirB"));
Assert.AreEqual(0, ((DirectoryEntry)fsD.Root.GetEntry("DirB")).EntryCount);
EntryUtils.CopyNodeRecursively(dirA, fsD.Root);
Assert.AreEqual(2, fsD.Root.EntryCount);
Assert.IsNotNull(fsD.Root.GetEntry("DirB"));
Assert.AreEqual(0, ((DirectoryEntry)fsD.Root.GetEntry("DirB")).EntryCount);
Assert.IsNotNull(fsD.Root.GetEntry("DirA"));
Assert.AreEqual(2, ((DirectoryEntry)fsD.Root.GetEntry("DirA")).EntryCount);
// Copy the whole lot
fsD = new POIFSFileSystem();
Assert.AreEqual(0, fsD.Root.EntryCount);
EntryUtils.CopyNodes(fs, fsD, new List<String>());
Assert.AreEqual(3, fsD.Root.EntryCount);
Assert.IsNotNull(fsD.Root.GetEntry(dirA.Name));
Assert.IsNotNull(fsD.Root.GetEntry(dirB.Name));
Assert.IsNotNull(fsD.Root.GetEntry(entryR.Name));
Assert.AreEqual(0, ((DirectoryEntry)fsD.Root.GetEntry("DirB")).EntryCount);
Assert.AreEqual(2, ((DirectoryEntry)fsD.Root.GetEntry("DirA")).EntryCount);
}
示例12: setUp
protected void setUp()
{
fs = new POIFSFileSystem();
dirA = fs.CreateDirectory("DirA");
dirB = fs.CreateDirectory("DirB");
dirAA = dirA.CreateDirectory("DirAA");
eRoot = fs.Root.CreateDocument("Root", new ByteArrayInputStream(new byte[] { }));
eA = dirA.CreateDocument("NA", new ByteArrayInputStream(new byte[] { }));
eAA = dirAA.CreateDocument("NAA", new ByteArrayInputStream(new byte[] { }));
}
示例13: TestPasswordVerification
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));
}
示例14: TestDecrypt
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);
}
示例15: TestEmptyConstructor
public void TestEmptyConstructor()
{
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryProperty property1 = new DirectoryProperty("parent");
DirectoryProperty property2 = new DirectoryProperty("child");
DirectoryNode parent = new DirectoryNode(property1, fs, null);
DirectoryNode node = new DirectoryNode(property2, fs, parent);
Assert.AreEqual(0, parent.Path.Length);
Assert.AreEqual(1, node.Path.Length);
Assert.AreEqual("child", node.Path.GetComponent(0));
// Verify that GetEntries behaves correctly
int count = 0;
IEnumerator iter = node.Entries;
while (iter.MoveNext())
{
count++;
}
Assert.AreEqual(0, count);
// Verify behavior of IsEmpty
Assert.IsTrue(node.IsEmpty);
// Verify behavior of EntryCount
Assert.AreEqual(0, node.EntryCount);
// Verify behavior of Entry
try
{
node.GetEntry("foo");
Assert.Fail("Should have caught FileNotFoundException");
}
catch (FileNotFoundException )
{
// as expected
}
// Verify behavior of isDirectoryEntry
Assert.IsTrue(node.IsDirectoryEntry);
// Verify behavior of GetName
Assert.AreEqual(property2.Name, node.Name);
// Verify behavior of isDocumentEntry
Assert.IsTrue(!node.IsDocumentEntry);
// Verify behavior of GetParent
Assert.AreEqual(parent, node.Parent);
}