当前位置: 首页>>代码示例>>C#>>正文


C# HSSFWorkbook.AddOlePackage方法代码示例

本文整理汇总了C#中NPOI.HSSF.UserModel.HSSFWorkbook.AddOlePackage方法的典型用法代码示例。如果您正苦于以下问题:C# HSSFWorkbook.AddOlePackage方法的具体用法?C# HSSFWorkbook.AddOlePackage怎么用?C# HSSFWorkbook.AddOlePackage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NPOI.HSSF.UserModel.HSSFWorkbook的用法示例。


在下文中一共展示了HSSFWorkbook.AddOlePackage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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()));

        }
开发者ID:Reinakumiko,项目名称:npoi,代码行数:73,代码来源:TestOLE2Embeding.cs


注:本文中的NPOI.HSSF.UserModel.HSSFWorkbook.AddOlePackage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。