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


C# IWorkbook.AddPicture方法代码示例

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


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

示例1: LoadImage

        public static int LoadImage(string path, IWorkbook wb)
        {
            FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read);
            byte[] buffer = new byte[file.Length];
            file.Read(buffer, 0, (int)file.Length);
            return wb.AddPicture(buffer, PictureType.JPEG);

        }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:8,代码来源:Program.cs

示例2: CreateRowItem

        private static void CreateRowItem(this ISheet target, IWorkbook workbook, DataTable dataSource)
        {
            IRow row = null;
            ICell cell = null;
            ICellStyle cellStyle = null;
            IDrawing drawing = null;
            IPicture picture = null;

            cellStyle = workbook.CreateCellStyle();
            cellStyle.Alignment = HorizontalAlignment.CENTER;
            cellStyle.VerticalAlignment = VerticalAlignment.CENTER;

            for (int rowIndex = 0; rowIndex < dataSource.Rows.Count; rowIndex++)
            {
                row = target.CreateRow(rowIndex + 1);

                for (int columnIndex = 0; columnIndex < dataSource.Columns.Count; columnIndex++)
                {
                    cell = row.CreateCell(columnIndex);

                    if (dataSource.Columns[columnIndex].DataType == typeof(byte[]))
                    {
                        byte[] image = dataSource.Rows[rowIndex][columnIndex] as byte[];

                        if (image != null && image.Length > 0)
                        {
                            int pictureIndex = workbook.AddPicture(dataSource.Rows[rowIndex][columnIndex] as byte[], PictureType.JPEG);

                            drawing = target.CreateDrawingPatriarch();
                            HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, columnIndex, rowIndex + 1, columnIndex, rowIndex + 1);
                            picture = drawing.CreatePicture(anchor, pictureIndex);
                            picture.Resize();
                        }
                    }

                    else
                    {
                        cell.SetCellValue(dataSource.Rows[rowIndex][columnIndex].ToString());
                    }

                    cell.CellStyle = cellStyle;
                }
            }
        }
开发者ID:kainhong,项目名称:CurrencyStore,代码行数:44,代码来源:AdoNetExtension.cs

示例3: handleResize

        private void handleResize(IWorkbook wb, ISheet sheet, IRow row)
        {
            IDrawing Drawing = sheet.CreateDrawingPatriarch();
            ICreationHelper CreateHelper = wb.GetCreationHelper();

            byte[] bytes = HSSFITestDataProvider.Instance.GetTestDataFileContent("logoKarmokar4.png");

            row.HeightInPoints = (/*setter*/GetImageSize(bytes).Y);

            int pictureIdx = wb.AddPicture(bytes, PictureType.PNG);

            //add a picture shape
            IClientAnchor anchor = CreateHelper.CreateClientAnchor();
            //set top-left corner of the picture,
            //subsequent call of Picture#resize() will operate relative to it
            anchor.Col1 = (/*setter*/0);
            anchor.Row1 = (/*setter*/0);

            IPicture pict = Drawing.CreatePicture(anchor, pictureIdx);

            //auto-size picture relative to its top-left corner
            pict.Resize();
        }
开发者ID:Reinakumiko,项目名称:npoi,代码行数:23,代码来源:BaseTestPicture.cs


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