本文整理汇总了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);
}
示例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;
}
}
}
示例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();
}