本文整理汇总了C#中NPOI.HSSF.UserModel.HSSFWorkbook.GetAllEmbeddedObjects方法的典型用法代码示例。如果您正苦于以下问题:C# HSSFWorkbook.GetAllEmbeddedObjects方法的具体用法?C# HSSFWorkbook.GetAllEmbeddedObjects怎么用?C# HSSFWorkbook.GetAllEmbeddedObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPOI.HSSF.UserModel.HSSFWorkbook
的用法示例。
在下文中一共展示了HSSFWorkbook.GetAllEmbeddedObjects方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestWordDocEmbeddedInXls
public void TestWordDocEmbeddedInXls()
{
//throw new NotImplementedException("class NPOIFSFileSystem is not implemented");
// Open the two filesystems
DirectoryNode[] files = new DirectoryNode[2];
files[0] = (new POIFSFileSystem(HSSFTestDataSamples.OpenSampleFileStream("WithEmbeddedObjects.xls"))).Root;
files[1] = (new NPOIFSFileSystem(HSSFTestDataSamples.OpenSampleFileStream("WithEmbeddedObjects.xls"))).Root;
// Check the embedded parts
foreach (DirectoryNode root in files)
{
HSSFWorkbook hw = new HSSFWorkbook(root, true);
IList<HSSFObjectData> objects = hw.GetAllEmbeddedObjects();
bool found = false;
for (int i = 0; i < objects.Count; i++)
{
HSSFObjectData embeddedObject = objects[i];
if (embeddedObject.HasDirectoryEntry())
{
DirectoryEntry dir = embeddedObject.GetDirectory();
if (dir is DirectoryNode)
{
DirectoryNode dNode = (DirectoryNode)dir;
if (HasEntry(dNode, "WordDocument"))
{
found = true;
}
}
}
}
Assert.IsTrue(found);
}
}
示例2: TestReallyEmbedSomething
public void TestReallyEmbedSomething()
{
HSSFWorkbook wb = new HSSFWorkbook();
ISheet sheet = wb.CreateSheet();
HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch;
byte[] pictureData = HSSFTestDataSamples.GetTestDataFileContent("logoKarmokar4.png");
byte[] picturePPT = POIDataSamples.GetSlideShowInstance().ReadFile("clock.jpg");
int imgIdx = wb.AddPicture(pictureData, PictureType.PNG);
POIFSFileSystem pptPoifs = GetSamplePPT();
int pptIdx = wb.AddOlePackage(pptPoifs, "Sample-PPT", "sample.ppt", "sample.ppt");
POIFSFileSystem xlsPoifs = GetSampleXLS();
int imgPPT = wb.AddPicture(picturePPT, PictureType.JPEG);
int xlsIdx = wb.AddOlePackage(xlsPoifs, "Sample-XLS", "sample.xls", "sample.xls");
int txtIdx = wb.AddOlePackage(GetSampleTXT(), "Sample-TXT", "sample.txt", "sample.txt");
int rowoffset = 5;
int coloffset = 5;
ICreationHelper ch = wb.GetCreationHelper();
HSSFClientAnchor anchor = (HSSFClientAnchor)ch.CreateClientAnchor();
anchor.SetAnchor((short)(2 + coloffset), 1 + rowoffset, 0, 0, (short)(3 + coloffset), 5 + rowoffset, 0, 0);
anchor.AnchorType = (/*setter*/AnchorType.DontMoveAndResize);
patriarch.CreateObjectData(anchor, pptIdx, imgPPT);
anchor = (HSSFClientAnchor)ch.CreateClientAnchor();
anchor.SetAnchor((short)(5 + coloffset), 1 + rowoffset, 0, 0, (short)(6 + coloffset), 5 + rowoffset, 0, 0);
anchor.AnchorType = (/*setter*/AnchorType.DontMoveAndResize);
patriarch.CreateObjectData(anchor, xlsIdx, imgIdx);
anchor = (HSSFClientAnchor)ch.CreateClientAnchor();
anchor.SetAnchor((short)(3 + coloffset), 10 + rowoffset, 0, 0, (short)(5 + coloffset), 11 + rowoffset, 0, 0);
anchor.AnchorType = (/*setter*/AnchorType.DontMoveAndResize);
patriarch.CreateObjectData(anchor, txtIdx, imgIdx);
anchor = (HSSFClientAnchor)ch.CreateClientAnchor();
anchor.SetAnchor((short)(1 + coloffset), -2 + rowoffset, 0, 0, (short)(7 + coloffset), 14 + rowoffset, 0, 0);
anchor.AnchorType = (/*setter*/AnchorType.DontMoveAndResize);
HSSFSimpleShape circle = patriarch.CreateSimpleShape(anchor);
circle.ShapeType = (/*setter*/HSSFSimpleShape.OBJECT_TYPE_OVAL);
circle.IsNoFill = (/*setter*/true);
if (false)
{
FileStream fos = new FileStream("embed.xls", FileMode.Create);
wb.Write(fos);
fos.Close();
}
wb = HSSFTestDataSamples.WriteOutAndReadBack(wb as HSSFWorkbook);
MemoryStream bos = new MemoryStream();
HSSFObjectData od = wb.GetAllEmbeddedObjects()[0];
Ole10Native ole10 = Ole10Native.CreateFromEmbeddedOleObject((DirectoryNode)od.GetDirectory());
bos = new MemoryStream();
pptPoifs.WriteFileSystem(bos);
Assert.IsTrue(Arrays.Equals(ole10.DataBuffer, bos.ToArray()));
od = wb.GetAllEmbeddedObjects()[1];
ole10 = Ole10Native.CreateFromEmbeddedOleObject((DirectoryNode)od.GetDirectory());
bos = new MemoryStream();
xlsPoifs.WriteFileSystem(bos);
Assert.IsTrue(Arrays.Equals(ole10.DataBuffer, bos.ToArray()));
od = wb.GetAllEmbeddedObjects()[2];
ole10 = Ole10Native.CreateFromEmbeddedOleObject((DirectoryNode)od.GetDirectory());
Assert.IsTrue(Arrays.Equals(ole10.DataBuffer, GetSampleTXT()));
}