本文整理匯總了C#中NPOI.HSSF.UserModel.HSSFSheet.GetColumnWidth方法的典型用法代碼示例。如果您正苦於以下問題:C# HSSFSheet.GetColumnWidth方法的具體用法?C# HSSFSheet.GetColumnWidth怎麽用?C# HSSFSheet.GetColumnWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類NPOI.HSSF.UserModel.HSSFSheet
的用法示例。
在下文中一共展示了HSSFSheet.GetColumnWidth方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetColumnWidth
protected static int GetColumnWidth(HSSFSheet sheet, int columnIndex)
{
return ExcelToHtmlUtils.GetColumnWidthInPx(sheet.GetColumnWidth(columnIndex));
}
示例2: WirtePic
/// <summary>
/// 在指定位置插入圖片,跨Column。ColumnIndex2需大於或等於ColumnIndex1
/// </summary>
public static void WirtePic(HSSFWorkbook workbook, HSSFSheet sheet, HSSFPatriarch patriarch, int columnIndex1, int columnIndex2, int rowIndex, string picPath)
{
if (!File.Exists(picPath))
{
return;
}
if (columnIndex2 < columnIndex1)
{
throw new Exception("ColumnIndex2需大於或等於ColumnIndex1");
}
int dx2 = 1023;
int dy2 = 255;
HSSFRow row = sheet.GetRow(rowIndex);
if (row != null)
{
int cWidth = 0;
for (int i = columnIndex1; i < columnIndex2; i++)
{
cWidth += sheet.GetColumnWidth(columnIndex1);
}
using (Image img = Image.FromFile(picPath))
{
double w = cWidth * 7.0 / 256.0;
double h = (row.Height * 1.32 / 20.0);
if (((double)img.Width / (double)img.Height) > (cWidth * 7.0 / 256 / (row.Height * 1.32 / 20)))
{
double h1 = w * img.Height / img.Width;
dy2 = (int)(h1 * 255 / h);
if (dy2 < 0) dy2 = 0;
if (dy2 > 255) dy2 = 255;
}
else
{
double w1 = h * img.Width / img.Height;
dx2 = (int)(w1 * 1023 / w);
if (dy2 < 0) dy2 = 0;
if (dy2 > 1023) dy2 = 1023;
}
}
}
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, dx2, dy2, columnIndex1, rowIndex, columnIndex2, rowIndex);
byte[] buff = File.ReadAllBytes(picPath);
int pic = workbook.AddPicture(buff, HSSFWorkbook.PICTURE_TYPE_JPEG);
anchor.AnchorType = 2;
patriarch.CreatePicture(anchor, pic);
}