本文整理汇总了C#中IRow.CreateCell方法的典型用法代码示例。如果您正苦于以下问题:C# IRow.CreateCell方法的具体用法?C# IRow.CreateCell怎么用?C# IRow.CreateCell使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRow
的用法示例。
在下文中一共展示了IRow.CreateCell方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: buildWorkbook
private void buildWorkbook(IWorkbook wb)
{
ISheet sh = wb.CreateSheet();
IRow row1 = sh.CreateRow(0);
IRow row2 = sh.CreateRow(1);
row3 = sh.CreateRow(2);
row1.CreateCell(0, CellType.Numeric);
row1.CreateCell(1, CellType.Numeric);
row2.CreateCell(0, CellType.Numeric);
row2.CreateCell(1, CellType.Numeric);
row3.CreateCell(0);
row3.CreateCell(1);
CellReference a1 = new CellReference("A1");
CellReference a2 = new CellReference("A2");
CellReference b1 = new CellReference("B1");
CellReference b2 = new CellReference("B2");
sh.GetRow(a1.Row).GetCell(a1.Col).SetCellValue(35);
sh.GetRow(a2.Row).GetCell(a2.Col).SetCellValue(0);
sh.GetRow(b1.Row).GetCell(b1.Col).CellFormula = (/*setter*/"A1/A2");
sh.GetRow(b2.Row).GetCell(b2.Col).CellFormula = (/*setter*/"NA()");
Evaluator = wb.GetCreationHelper().CreateFormulaEvaluator();
}
示例2: CreateCell
internal static ICell CreateCell(IWorkbook workbook, IRow row, int column, decimal? content, bool isCentered)
{
ICellStyle style = workbook.CreateCellStyle();
ICell cell = row.CreateCell(column);
if (content == null)
{
cell.SetCellValue("");
}
else
{
cell.SetCellValue(Convert.ToDouble(content.Value));
}
if (isCentered)
{
style.Alignment = HorizontalAlignment.Center;
}
style.BorderBottom = BorderStyle.Thin;
style.BorderTop = BorderStyle.Thin;
style.BorderLeft = BorderStyle.Thin;
style.BorderRight = BorderStyle.Thin;
cell.CellStyle = style;
return cell;
}
示例3: InsertCell
private static int InsertCell(IRow row, int cellIndex, string value, ICellStyle cellStyle)
{
var cell = row.CreateCell(cellIndex);
cell.SetCellValue(value);
cell.CellStyle = cellStyle;
cellIndex++;
return cellIndex;
}
示例4: CreateCells
public void CreateCells(int cellsCount, ref IRow row, IList<string> cellsValues = null)
{
//var isEmptyCells = cellsValues == null || !cellsValues.Any() || cellsValues.Count != cellsCount;
//if (isEmptyCells)
// for (var j = 0; j < cellsCount; j++)
// row.CreateCell(j).SetCellValue(string.Empty);
//else
for (var j = 0; j < cellsCount; j++)
row.CreateCell(j).SetCellValue("cell " + j);
}
示例5: WriteCell
protected ICell WriteCell(IRow row, int column, Action<ICell> setValue, ICellStyle style = null)
{
var cell = row.CreateCell(column);
setValue(cell);
if (style != null)
{
cell.CellStyle = style;
}
return cell;
}
示例6: SetCellValue
public void SetCellValue(IRow row, int index, CellType cellType, dynamic value)
{
if (value == null) value = string.Empty;
if (value is string)
{
value = Convert.ChangeType(value, TypeCode.String);
}
else
{
value = Convert.ChangeType(value, TypeCode.Double);
}
ICell cell = row.CreateCell(index);
cell.SetCellType(cellType);
cell.SetCellValue(value);
}
示例7: GetOrCreateCell
/// <summary>
/// 获取单元格,如果不存在则创建
/// </summary>
private ICell GetOrCreateCell( IRow row, int columnIndex ) {
return row.GetCell( columnIndex ) ?? row.CreateCell( columnIndex );
}
示例8: WriteTitle
/// <summary>
/// 写入数据到Row
/// </summary>
/// <param name="row"></param>
/// <param name="columns"></param>
public void WriteTitle(IRow row, DataColumnCollection columns)
{
for (int j = 0; j < columns.Count; j++)
{
var cell = row.CreateCell(j);
cell.SetCellValue(columns[j].ColumnName);
cell.CellStyle = titleStyle;
}
}
示例9: CreateRow
/// <summary>
/// 创建一行数据
/// </summary>
/// <param name="row">Row 对象</param>
/// <param name="rowDatas">填入 Row 的只读数据集合</param>
/// <param name="userStringFormat">是否是否使用 string 数据格式,默认 false</param>
private void CreateRow(IRow row, object[] rowDatas, bool userStringFormat = false)
{
for (var i = 0; i < rowDatas.Length; i++)
{
var cell = row.CreateCell(i);
var data = rowDatas[i];
var dataType = data == null || userStringFormat ? typeof(string) : data.GetType();
WriteToCell(cell, dataType, data);
}
}
示例10: CreateCellForRow
/// <summary>
/// 根据datarow 创建 cells.
/// </summary>
/// <param name="excelRow"></param>
/// <param name="columns"></param>
/// <param name="row">如果为null 则该行所有cell的值为空</param>
/// <param name="isHead">如果是true 则创建表头.</param>
private void CreateCellForRow(IRow excelRow, DataColumnCollection columns, DataRow row,bool isHead)
{
for (int i=0;i<columns.Count;i++)
{
var cell = excelRow.CreateCell(i);
if (isHead)
{
cell.SetCellValue(columns[i].ColumnName);
}
else
{
string cellValue = string.Empty;
if (row != null) { cellValue = row[i].ToString(); }
cell.SetCellValue(cellValue);
}
}
}
示例11: SetRow
/// <summary>
/// 设置行
/// </summary>
/// <param name="row"></param>
/// <param name="obj"></param>
private static void SetRow(IRow row, object obj)
{
//获取属性
var columns = obj.GetType().GetProperties();
//一个属性一个格
for (int i = 0; i < obj.GetType().GetProperties().Length; i++)
{
//创建格
ICell cell = row.CreateCell(i);
//设置单元格的内容
SetCell(cell, columns[i], obj);
}
}
示例12: CreateRow
/// <summary>
/// 创建 Row
/// </summary>
/// <param name="row">Row 对象</param>
/// <param name="datas">填入 Row 的只读数据集合</param>
/// <param name="isFormat">是否数据有格式化,默认 true</param>
private void CreateRow(IRow row, IReadOnlyList<object> datas, bool isFormat = true)
{
for (var i = 0; i < this._columnNames.Length; i++)
{
var cell = row.CreateCell(i);
var dataType = isFormat ? this._columnTypes[i] : typeof (string);
this.WriteToCell(cell, dataType, datas[i]);
}
}
示例13: CreateCell
/// <summary>NPOI新增儲存格資料</summary>
/// <param name="Word">顯示文字</param>
/// <param name="ContentRow">NPOI IROW</param>
/// <param name="CellIndex">儲存格列數</param>
/// <param name="cellStyleBoder">ICellStyle樣式</param>
private static void CreateCell(string Word, IRow ContentRow, int CellIndex, ICellStyle cellStyleBoder)
{
ICell _cell = ContentRow.CreateCell(CellIndex);
_cell.SetCellValue(Word);
_cell.CellStyle = cellStyleBoder;
}
示例14: CreateCellForRow
/// <summary>
/// 根据datarow 创建 cells.
/// </summary>
/// <param name="excelRow"></param>
/// <param name="columns"></param>
/// <param name="row">如果为null 则该行所有cell的值为空</param>
/// <param name="isHead">如果是true 则创建表头.</param>
private void CreateCellForRow(IRow excelRow, DataColumnCollection columns, DataRow row, bool isHead)
{
for (int i = 0; i < columns.Count; i++)
{
var cell = excelRow.CreateCell(i);
if (isHead)
{
cell.SetCellValue(columns[i].ColumnName);
}
else
{
string cellValue = string.Empty;
if (row != null) { cellValue = row[i].ToString(); }
//该地址是图片
if (NeedInsertImage&& Regex.IsMatch(cellValue, @"\.jpg|\.png|\.tiff|\.tif", RegexOptions.IgnoreCase))
{
string filePath = System.Web.HttpContext.Current.Server.MapPath("/ProductImages/original/" + cellValue);
if (File.Exists(filePath))
{
try
{
System.Drawing.Image image = System.Drawing.Image.FromFile(filePath);
System.Drawing.Bitmap targetImage = ThumbnailMaker.DrawThumbnail(image, ThumbnailType.GeometricScalingByWidth, 150, 0);
excelRow.Sheet.SetColumnWidth(i, MSExcelUtil.pixel2WidthUnits(targetImage.Width - 2));
excelRow.HeightInPoints = (float)((targetImage.Height - 2) * 0.75);
using (MemoryStream ms = new MemoryStream())
{
targetImage.Save(ms, image.RawFormat);
InsertImageToCell(ms, i, excelRow.RowNum);
}
targetImage.Dispose();
image.Dispose();
}
catch (Exception ex)
{
NLogger.Logger.Debug(filePath+ex.Message);
}
}
}
else
{
cell.SetCellValue(cellValue);
}
}
}
}
示例15: topBottomBorder
internal static void topBottomBorder(IWorkbook workbook, ICell cell, IRow row, int numCells)
{
ICellStyle cellStyle = workbook.CreateCellStyle();
cellStyle.BorderBottom = BorderStyle.Thin;
cellStyle.BorderTop = BorderStyle.Thin;
cellStyle.BorderLeft = BorderStyle.Thin;
cellStyle.BorderRight = BorderStyle.Thin;
for (int i = 1; i <= numCells; i++)
{
ICell newCell = row.CreateCell(cell.ColumnIndex + i);
newCell.CellStyle = cellStyle;
}
}