本文整理汇总了C#中NPOI.POIFS.FileSystem.POIFSFileSystem.WriteFileSystem方法的典型用法代码示例。如果您正苦于以下问题:C# POIFSFileSystem.WriteFileSystem方法的具体用法?C# POIFSFileSystem.WriteFileSystem怎么用?C# POIFSFileSystem.WriteFileSystem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPOI.POIFS.FileSystem.POIFSFileSystem
的用法示例。
在下文中一共展示了POIFSFileSystem.WriteFileSystem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: Write
/**
* Write out, with any properties changes, but nothing else
*/
public override void Write(Stream out1)
{
POIFSFileSystem fs = new POIFSFileSystem();
// For tracking what we've written out, so far
List<String> excepts = new List<String>(1);
// Write out our HPFS properties, with any changes
WriteProperties(fs, excepts);
// Copy over everything else unchanged
EntryUtils.CopyNodes(directory, fs.Root, excepts);
// Save the resultant POIFSFileSystem to the output stream
fs.WriteFileSystem(out1);
}
示例3: Main
static void Main(string[] args)
{
POIFSFileSystem fs = new POIFSFileSystem();
//get the root directory
DirectoryEntry dir = fs.Root;
//create a document entry
dir.CreateDocument("Foo", new MemoryStream(new byte[] {0x01,0x02,0x03 }));
//create a folder
dir.CreateDirectory("Hello");
//create a POIFS file called Foo.poifs
FileStream output = new FileStream("Foo.poifs", FileMode.OpenOrCreate);
fs.WriteFileSystem(output);
output.Close();
}
示例4: TestRecreate
/**
* Performs the check described in {@link #TestReCreate()} for a single
* POI filesystem.
*
* @param f the POI filesystem to check
*/
private void TestRecreate(FileInfo f)
{
Console.WriteLine("Recreating file \"" + f.Name + "\"");
/* Read the POI filesystem's property Set streams: */
POIFile[] psf1 = Util.ReadPropertySets(_samples.GetFile(f.Name));
/* Create a new POI filesystem containing the origin file's
* property Set streams: */
FileInfo fi = new FileInfo(f.Name);
FileStream copy = File.Create(fi.Name);
//copy.deleteOnExit();
FileStream out1 = copy;
POIFSFileSystem poiFs = new POIFSFileSystem();
for (int i = 0; i < psf1.Length; i++)
{
Stream in1 =
new ByteArrayInputStream(psf1[i].GetBytes());
PropertySet psIn = PropertySetFactory.Create(in1);
MutablePropertySet psOut = new MutablePropertySet(psIn);
MemoryStream psStream =
new MemoryStream();
psOut.Write(psStream);
psStream.Close();
byte[] streamData = psStream.ToArray();
poiFs.CreateDocument(new ByteArrayInputStream(streamData),
psf1[i].GetName());
poiFs.WriteFileSystem(out1);
}
/* Read the property Set streams from the POI filesystem just
* Created. */
POIFile[] psf2 = Util.ReadPropertySets(copy);
for (int i = 0; i < psf2.Length; i++)
{
byte[] bytes1 = psf1[i].GetBytes();
byte[] bytes2 = psf2[i].GetBytes();
Stream in1 = new ByteArrayInputStream(bytes1);
Stream in2 = new ByteArrayInputStream(bytes2);
PropertySet ps1 = PropertySetFactory.Create(in1);
PropertySet ps2 = PropertySetFactory.Create(in2);
/* Compare the property Set stream with the corresponding one
* from the origin file and check whether they are equal. */
Assert.AreEqual(ps1, ps2, "Equality for file " + f.Name);
}
out1.Close();
}
示例5: TestWriteTwoSections
public void TestWriteTwoSections()
{
String STREAM_NAME = "PropertySetStream";
String SECTION1 = "Section 1";
String SECTION2 = "Section 2";
FileInfo fi = TempFile.CreateTempFile(POI_FS, ".doc");
FileStream file = new FileStream(fi.FullName, FileMode.Open, FileAccess.ReadWrite);
//filename.deleteOnExit();
FileStream out1 = file;
POIFSFileSystem poiFs = new POIFSFileSystem();
MutablePropertySet ps = new MutablePropertySet();
ps.ClearSections();
ClassID formatID = new ClassID();
formatID.Bytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15};
MutableSection s1 = new MutableSection();
s1.SetFormatID(formatID);
s1.SetProperty(2, SECTION1);
ps.AddSection(s1);
MutableSection s2 = new MutableSection();
s2.SetFormatID(formatID);
s2.SetProperty(2, SECTION2);
ps.AddSection(s2);
poiFs.CreateDocument(ps.GetStream(), STREAM_NAME);
poiFs.WriteFileSystem(out1);
//out1.Close();
/* Read the POIFS: */
psa = new PropertySet[1];
POIFSReader reader2 = new POIFSReader();
//reader2.StreamReaded += new POIFSReaderEventHandler(reader2_StreamReaded);
POIFSReaderListener2 prl = new POIFSReaderListener2();
reader2.RegisterListener(prl);
reader2.Read(file);
Assert.IsNotNull(psa[0]);
Section s = (Section)(psa[0].Sections[0]);
Assert.AreEqual(s.FormatID, formatID);
Object p = s.GetProperty(2);
Assert.AreEqual(SECTION1, p);
s = (Section)(psa[0].Sections[1]);
p = s.GetProperty(2);
Assert.AreEqual(SECTION2, p);
file.Close();
//File.Delete(dataDir + POI_FS);
try
{
File.Delete(fi.FullName);
}
catch
{
}
}
示例6: TestDictionaryWithInvalidCodepage
public void TestDictionaryWithInvalidCodepage()
{
using (FileStream copy = File.Create(@".\Test-HPSF.ole2"))
{
/* Write: */
POIFSFileSystem poiFs = new POIFSFileSystem();
MutablePropertySet ps1 = new MutablePropertySet();
MutableSection s = (MutableSection)ps1.Sections[0];
Hashtable m = new Hashtable(3, 1.0f);
m[1] = "String 1";
m[2] = "String 2";
m[3] = "String 3";
try
{
s.Dictionary = m;
s.SetFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID1);
s.SetProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2, 12345);
poiFs.CreateDocument(ps1.ToInputStream(), "Test");
poiFs.WriteFileSystem(copy);
Assert.Fail("This Testcase did not detect the invalid codepage value.");
}
catch (IllegalPropertySetDataException)
{
Assert.IsTrue(true);
}
}
if (File.Exists(@".\Test-HPSF.ole2"))
{
File.Delete(@".\Test-HPSF.ole2");
}
}
示例7: TestShortLastBlock
public void TestShortLastBlock()
{
String[] files = new String[] { "ShortLastBlock.qwp", "ShortLastBlock.wps" };
for (int i = 0; i < files.Length; i++)
{
// Open the file up
POIFSFileSystem fs = new POIFSFileSystem(
_samples.OpenResourceAsStream(files[i])
);
// Write it into a temp output array
MemoryStream baos = new MemoryStream();
fs.WriteFileSystem(baos);
// Check sizes
}
}
示例8: TestSingleEmptyDocument
public void TestSingleEmptyDocument()
{
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry dir = fs.Root;
dir.CreateDocument("Foo", new MemoryStream(new byte[] { }));
MemoryStream output = new MemoryStream();
fs.WriteFileSystem(output);
byte[] temp = output.ToArray();
Assert.IsNotNull(new POIFSFileSystem(new MemoryStream(temp)));
}
示例9: TestEmptyDocumentEventWithFriend
public void TestEmptyDocumentEventWithFriend()
{
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry dir = fs.Root;
dir.CreateDocument("Bar", 1, new AnonymousClass1());
dir.CreateDocument("Foo", 0, new EmptyClass());
MemoryStream output = new MemoryStream();
fs.WriteFileSystem(output);
Assert.IsNotNull(new POIFSFileSystem(new MemoryStream(output.ToArray())));
}
示例10: TestWriteWellKnown1
//.........这里部分代码省略.........
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);
示例11: Write
/// <summary>
/// Write out this workbook to an Outputstream. Constructs
/// a new POI POIFSFileSystem, passes in the workbook binary representation and
/// Writes it out.
/// </summary>
/// <param name="stream">the java OutputStream you wish to Write the XLS to</param>
public override void Write(Stream stream)
{
byte[] bytes = GetBytes();
POIFSFileSystem fs = new POIFSFileSystem();
if (this.DocumentSummaryInformation == null)
{
this.DocumentSummaryInformation = HPSF.PropertySetFactory.CreateDocumentSummaryInformation();
}
NPOI.HPSF.CustomProperties cp = this.DocumentSummaryInformation.CustomProperties;
if(cp==null)
{
cp= new NPOI.HPSF.CustomProperties();
}
cp.Put("Generator", "NPOI");
cp.Put("Generator Version", Assembly.GetExecutingAssembly().GetName().Version.ToString(3));
this.DocumentSummaryInformation.CustomProperties = cp;
if (this.SummaryInformation == null)
{
this.SummaryInformation = HPSF.PropertySetFactory.CreateSummaryInformation();
}
this.SummaryInformation.ApplicationName = "NPOI";
// For tracking what we've written out, used if we're
// going to be preserving nodes
List<string> excepts = new List<string>(1);
using (MemoryStream newMemoryStream = new MemoryStream(bytes))
{
// Write out the Workbook stream
fs.CreateDocument(newMemoryStream, "Workbook");
// Write out our HPFS properties, if we have them
WriteProperties(fs, excepts);
if (preserveNodes)
{
// Don't Write out the old Workbook, we'll be doing our new one
// If the file had an "incorrect" name for the workbook stream,
// don't write the old one as we'll use the correct name shortly
excepts.AddRange(WORKBOOK_DIR_ENTRY_NAMES);
// Copy over all the other nodes to our new poifs
EntryUtils.CopyNodes(
new FilteringDirectoryNode(this.directory, excepts)
, new FilteringDirectoryNode(fs.Root, excepts)
);
// YK: preserve StorageClsid, it is important for embedded workbooks,
// see Bugzilla 47920
fs.Root.StorageClsid = (this.directory.StorageClsid);
}
fs.WriteFileSystem(stream);
}
bytes = null;
}
示例12: Write
/// <summary>
/// Write out this workbook to an Outputstream. Constructs
/// a new POI POIFSFileSystem, passes in the workbook binary representation and
/// Writes it out.
/// </summary>
/// <param name="stream">the java OutputStream you wish to Write the XLS to</param>
public override void Write(Stream stream)
{
byte[] bytes = GetBytes();
POIFSFileSystem fs = new POIFSFileSystem();
// For tracking what we've written out, used if we're
// going to be preserving nodes
IList excepts = new ArrayList(1);
// Write out the Workbook stream
fs.CreateDocument(new MemoryStream(bytes), "Workbook");
// Write out our HPFS properties, if we have them
WriteProperties(fs, excepts);
if (preserveNodes)
{
// Don't Write out the old Workbook, we'll be doing our new one
excepts.Add("Workbook");
// If the file had WORKBOOK instead of Workbook, we'll Write it
// out correctly shortly, so don't include the old one
excepts.Add("WORKBOOK");
// Copy over all the other nodes to our new poifs
CopyNodes(this.filesystem, fs, excepts);
}
fs.WriteFileSystem(stream);
}
示例13: TestAreDocumentsIdentical
public void TestAreDocumentsIdentical()
{
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry dirA = fs.CreateDirectory("DirA");
DirectoryEntry dirB = fs.CreateDirectory("DirB");
DocumentEntry entryA1 = dirA.CreateDocument("Entry1", new ByteArrayInputStream(dataSmallA));
DocumentEntry entryA1b = dirA.CreateDocument("Entry1b", new ByteArrayInputStream(dataSmallA));
DocumentEntry entryA2 = dirA.CreateDocument("Entry2", new ByteArrayInputStream(dataSmallB));
DocumentEntry entryB1 = dirB.CreateDocument("Entry1", new ByteArrayInputStream(dataSmallA));
// Names must match
Assert.AreEqual(false, entryA1.Name.Equals(entryA1b.Name));
Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(entryA1, entryA1b));
// Contents must match
Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(entryA1, entryA2));
// Parents don't matter if contents + names are the same
Assert.AreEqual(false, entryA1.Parent.Equals(entryB1.Parent));
Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(entryA1, entryB1));
// Can work with NPOIFS + POIFS
//ByteArrayOutputStream tmpO = new ByteArrayOutputStream();
MemoryStream tmpO = new MemoryStream();
fs.WriteFileSystem(tmpO);
ByteArrayInputStream tmpI = new ByteArrayInputStream(tmpO.ToArray());
NPOIFSFileSystem nfs = new NPOIFSFileSystem(tmpI);
DirectoryEntry dN1 = (DirectoryEntry)nfs.Root.GetEntry("DirA");
DirectoryEntry dN2 = (DirectoryEntry)nfs.Root.GetEntry("DirB");
DocumentEntry eNA1 = (DocumentEntry)dN1.GetEntry(entryA1.Name);
DocumentEntry eNA2 = (DocumentEntry)dN1.GetEntry(entryA2.Name);
DocumentEntry eNB1 = (DocumentEntry)dN2.GetEntry(entryB1.Name);
Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(eNA1, eNA2));
Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(eNA1, eNB1));
Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(eNA1, entryA1b));
Assert.AreEqual(false, EntryUtils.AreDocumentsIdentical(eNA1, entryA2));
Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(eNA1, entryA1));
Assert.AreEqual(true, EntryUtils.AreDocumentsIdentical(eNA1, entryB1));
}
示例14: TestDictionary
public void TestDictionary()
{
FileStream copy = File.Create( @"\Test-HPSF.ole2");
//copy.deleteOnExit();
/* Write: */
FileStream out1 = copy;
POIFSFileSystem poiFs = new POIFSFileSystem();
MutablePropertySet ps1 = new MutablePropertySet();
MutableSection s = (MutableSection)ps1.Sections[0];
Hashtable m = new Hashtable(3, 1.0f);
m[1] = "String 1";
m[2] = "String 2";
m[3] = "String 3";
s.Dictionary = (m);
s.SetFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID1);
int codepage = (int)Constants.CP_UNICODE;
s.SetProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2,
codepage);
poiFs.CreateDocument(ps1.GetStream(), "Test");
poiFs.WriteFileSystem(out1);
/* Read back: */
POIFile[] psf = Util.ReadPropertySets(copy);
Assert.AreEqual(1, psf.Length);
byte[] bytes = psf[0].GetBytes();
Stream in1 = new ByteArrayInputStream(bytes);
PropertySet ps2 = PropertySetFactory.Create(in1);
/* Check if the result is a DocumentSummaryInformation stream, as
* specified. */
Assert.IsTrue(ps2.IsDocumentSummaryInformation);
/* Compare the property Set stream with the corresponding one
* from the origin file and check whether they are equal. */
Assert.IsTrue(ps1.Equals(ps2));
out1.Close();
copy.Close();
File.Delete( @"\Test-HPSF.ole2");
}
示例15: TestDictionaryWithInvalidCodepage
public void TestDictionaryWithInvalidCodepage()
{
try
{
FileStream copy = File.Create( @"\Test-HPSF.ole2");
//copy.deleteOnExit();
/* Write: */
FileStream out1 = copy;
POIFSFileSystem poiFs = new POIFSFileSystem();
MutablePropertySet ps1 = new MutablePropertySet();
MutableSection s = (MutableSection)ps1.Sections[0];
Hashtable m = new Hashtable(3, 1.0f);
m[1] = "String 1";
m[2] = "String 2";
m[3] = "String 3";
s.Dictionary = (m);
s.SetFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID1);
int codepage = 12345;
s.SetProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2,
codepage);
poiFs.CreateDocument(ps1.GetStream(), "Test");
poiFs.WriteFileSystem(out1);
out1.Close();
Assert.Fail("This Testcase did not detect the invalid codepage value.");
}
catch (IllegalPropertySetDataException)
{
//Assert.IsTrue(true);
}
}