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


C# XSSFWorkbook.GetAllPictures方法代码示例

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


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

示例1: TestCreate

        public void TestCreate()
        {
            XSSFWorkbook wb = new XSSFWorkbook();
            XSSFSheet sheet = (XSSFSheet)wb.CreateSheet();
            XSSFDrawing drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch();

            byte[] jpegData = Encoding.UTF8.GetBytes("test jpeg data");

            IList pictures = wb.GetAllPictures();
            Assert.AreEqual(0, pictures.Count);

            int jpegIdx = wb.AddPicture(jpegData, PictureType.JPEG);
            Assert.AreEqual(1, pictures.Count);
            Assert.AreEqual("jpeg", ((XSSFPictureData)pictures[jpegIdx]).SuggestFileExtension());
            Assert.IsTrue(Arrays.Equals(jpegData, ((XSSFPictureData)pictures[jpegIdx]).Data));

            XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30);
            Assert.AreEqual(AnchorType.MoveAndResize, (AnchorType)anchor.AnchorType);
            anchor.AnchorType = (int)AnchorType.DontMoveAndResize;
            Assert.AreEqual(AnchorType.DontMoveAndResize, (AnchorType)anchor.AnchorType);

            XSSFPicture shape = (XSSFPicture)drawing.CreatePicture(anchor, jpegIdx);
            Assert.IsTrue(anchor.Equals(shape.GetAnchor()));
            Assert.IsNotNull(shape.PictureData);
            Assert.IsTrue(Arrays.Equals(jpegData, shape.PictureData.Data));

            CT_TwoCellAnchor ctShapeHolder = (CT_TwoCellAnchor)drawing.GetCTDrawing().CellAnchors[0];
            // STEditAs.ABSOLUTE corresponds to ClientAnchor.DONT_MOVE_AND_RESIZE
            Assert.AreEqual(ST_EditAs.absolute, ctShapeHolder.editAs);
        }
开发者ID:89sos98,项目名称:npoi,代码行数:30,代码来源:TestXSSFPicture.cs

示例2: TestNew

        public void TestNew()
        {
            XSSFWorkbook wb = new XSSFWorkbook();
            XSSFSheet sheet = (XSSFSheet)wb.CreateSheet();
            XSSFDrawing Drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch();

            byte[] jpegData = Encoding.UTF8.GetBytes("test jpeg data");
            byte[] wmfData = Encoding.UTF8.GetBytes("test wmf data");
            byte[] pngData = Encoding.UTF8.GetBytes("test png data");

            IList pictures = wb.GetAllPictures();
            Assert.AreEqual(0, pictures.Count);

            int jpegIdx = wb.AddPicture(jpegData, PictureType.JPEG);
            Assert.AreEqual(1, pictures.Count);
            Assert.AreEqual("jpeg", ((XSSFPictureData)pictures[jpegIdx]).SuggestFileExtension());
            Assert.IsTrue(Arrays.Equals(jpegData, ((XSSFPictureData)pictures[jpegIdx]).Data));

            int wmfIdx = wb.AddPicture(wmfData, PictureType.WMF);
            Assert.AreEqual(2, pictures.Count);
            Assert.AreEqual("wmf", ((XSSFPictureData)pictures[wmfIdx]).SuggestFileExtension());
            Assert.IsTrue(Arrays.Equals(wmfData, ((XSSFPictureData)pictures[wmfIdx]).Data));

            int pngIdx = wb.AddPicture(pngData, PictureType.PNG);
            Assert.AreEqual(3, pictures.Count);
            Assert.AreEqual("png", ((XSSFPictureData)pictures[pngIdx]).SuggestFileExtension());
            Assert.IsTrue(Arrays.Equals(pngData, ((XSSFPictureData)pictures[pngIdx]).Data));

            //TODO finish usermodel API for XSSFPicture
            XSSFPicture p1 = (XSSFPicture)Drawing.CreatePicture(new XSSFClientAnchor(), jpegIdx);
            XSSFPicture p2 = (XSSFPicture)Drawing.CreatePicture(new XSSFClientAnchor(), wmfIdx);
            XSSFPicture p3 = (XSSFPicture)Drawing.CreatePicture(new XSSFClientAnchor(), pngIdx);

            //check that the Added pictures are accessible After write
            wb = (XSSFWorkbook)XSSFTestDataSamples.WriteOutAndReadBack(wb);
            IList pictures2 = wb.GetAllPictures();
            Assert.AreEqual(3, pictures2.Count);

            Assert.AreEqual("jpeg", ((XSSFPictureData)pictures2[jpegIdx]).SuggestFileExtension());
            Assert.IsTrue(Arrays.Equals(jpegData, ((XSSFPictureData)pictures2[jpegIdx]).Data));

            Assert.AreEqual("wmf", ((XSSFPictureData)pictures2[wmfIdx]).SuggestFileExtension());
            Assert.IsTrue(Arrays.Equals(wmfData, ((XSSFPictureData)pictures2[wmfIdx]).Data));

            Assert.AreEqual("png", ((XSSFPictureData)pictures2[pngIdx]).SuggestFileExtension());
            Assert.IsTrue(Arrays.Equals(pngData, ((XSSFPictureData)pictures2[pngIdx]).Data));
        }
开发者ID:ctddjyds,项目名称:npoi,代码行数:47,代码来源:TestXSSFPictureData.cs

示例3: Main

        static void Main(string[] args)
        {
            FileStream file = File.OpenRead(@"clothes.xlsx");
            IWorkbook workbook = new XSSFWorkbook(file);

            IList pictures = workbook.GetAllPictures();
            int i = 0;
            foreach (IPictureData pic in pictures)
            {
                string ext = pic.SuggestFileExtension();
                if (ext.Equals("jpeg"))
                {
                    Image jpg = Image.FromStream(new MemoryStream(pic.Data));
                    jpg.Save(string.Format("pic{0}.jpg",i++));
                }
                else if (ext.Equals("png"))
                {
                    Image png = Image.FromStream(new MemoryStream(pic.Data));
                    png.Save(string.Format("pic{0}.png", i++));
                }

            }

        }
开发者ID:89sos98,项目名称:npoi,代码行数:24,代码来源:Program.cs

示例4: TestMultiRelationShips

        public void TestMultiRelationShips()
        {
            XSSFWorkbook wb = new XSSFWorkbook();

            byte[] pic1Data = Encoding.UTF8.GetBytes("test jpeg data");
            byte[] pic2Data = Encoding.UTF8.GetBytes("test png data");

            List<XSSFPictureData> pictures = wb.GetAllPictures() as List<XSSFPictureData>;
            Assert.AreEqual(0, pictures.Count);

            int pic1 = wb.AddPicture(pic1Data, XSSFWorkbook.PICTURE_TYPE_JPEG);
            int pic2 = wb.AddPicture(pic2Data, XSSFWorkbook.PICTURE_TYPE_PNG);

            XSSFSheet sheet1 = wb.CreateSheet() as XSSFSheet;
            XSSFDrawing drawing1 = sheet1.CreateDrawingPatriarch() as XSSFDrawing;
            XSSFPicture shape1 = drawing1.CreatePicture(new XSSFClientAnchor(), pic1) as XSSFPicture;
            XSSFPicture shape2 = drawing1.CreatePicture(new XSSFClientAnchor(), pic2) as XSSFPicture;

            XSSFSheet sheet2 = wb.CreateSheet() as XSSFSheet;
            XSSFDrawing drawing2 = sheet2.CreateDrawingPatriarch() as XSSFDrawing;
            XSSFPicture shape3 = drawing2.CreatePicture(new XSSFClientAnchor(), pic2) as XSSFPicture;
            XSSFPicture shape4 = drawing2.CreatePicture(new XSSFClientAnchor(), pic1) as XSSFPicture;

            Assert.AreEqual(2, pictures.Count);

            wb = XSSFTestDataSamples.WriteOutAndReadBack(wb) as XSSFWorkbook;
            pictures = wb.GetAllPictures() as List<XSSFPictureData>;
            Assert.AreEqual(2, pictures.Count);

            sheet1 = wb.GetSheetAt(0) as XSSFSheet;
            drawing1 = sheet1.CreateDrawingPatriarch() as XSSFDrawing;
            XSSFPicture shape11 = (XSSFPicture)drawing1.GetShapes()[0];
            Assert.IsTrue(Arrays.Equals(shape1.PictureData.Data, shape11.PictureData.Data));
            XSSFPicture shape22 = (XSSFPicture)drawing1.GetShapes()[1];
            Assert.IsTrue(Arrays.Equals(shape2.PictureData.Data, shape22.PictureData.Data));

            sheet2 = wb.GetSheetAt(1) as XSSFSheet;
            drawing2 = sheet2.CreateDrawingPatriarch() as XSSFDrawing;
            XSSFPicture shape33 = (XSSFPicture)drawing2.GetShapes()[0];
            Assert.IsTrue(Arrays.Equals(shape3.PictureData.Data, shape33.PictureData.Data));
            XSSFPicture shape44 = (XSSFPicture)drawing2.GetShapes()[1];
            Assert.IsTrue(Arrays.Equals(shape4.PictureData.Data, shape44.PictureData.Data));
        }
开发者ID:89sos98,项目名称:npoi,代码行数:43,代码来源:TestXSSFPicture.cs

示例5: TestLoadPictures

 public void TestLoadPictures()
 {
     XSSFWorkbook workbook = new XSSFWorkbook(_ssSampels.OpenResourceAsStream("picture.xlsx"));
     IList pictures = workbook.GetAllPictures();
     Assert.AreEqual(1, pictures.Count);
 }
开发者ID:89sos98,项目名称:npoi,代码行数:6,代码来源:TestLoadSaveXSSF.cs


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