本文整理汇总了C#中CellRangeAddress类的典型用法代码示例。如果您正苦于以下问题:C# CellRangeAddress类的具体用法?C# CellRangeAddress怎么用?C# CellRangeAddress使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CellRangeAddress类属于命名空间,在下文中一共展示了CellRangeAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetBorderBottom
//[Obsolete]
//public static void SetBorderBottom(NPOI.SS.UserModel.CellBorderType border, Region region, HSSFSheet sheet,
// HSSFWorkbook workbook)
//{
// SetBorderBottom(border, toCRA(region), sheet, workbook);
//}
/// <summary>
/// Sets the borderBottom attribute of the HSSFRegionUtil object
/// </summary>
/// <param name="border">The new border</param>
/// <param name="region">The region that should have the border</param>
/// <param name="sheet">The sheet that the region is on.</param>
/// <param name="workbook">The workbook that the region is on.</param>
public static void SetBorderBottom(NPOI.SS.UserModel.CellBorderType border, CellRangeAddress region, HSSFSheet sheet,
HSSFWorkbook workbook)
{
int colStart = region.FirstColumn;
int colEnd = region.LastColumn;
int rowIndex = region.LastRow;
CellPropertySetter cps = new CellPropertySetter(workbook, HSSFCellUtil.BORDER_BOTTOM, (int)border);
NPOI.SS.UserModel.Row row = HSSFCellUtil.GetRow(rowIndex, sheet);
for (int i = colStart; i <= colEnd; i++)
{
cps.SetProperty(row, i);
}
}
示例2: FeatRecord
public FeatRecord(RecordInputStream in1)
{
futureHeader = new FtrHeader(in1);
isf_sharedFeatureType = in1.ReadShort();
reserved1 = (byte)in1.ReadByte();
reserved2 = in1.ReadInt();
int cref = in1.ReadUShort();
cbFeatData = in1.ReadInt();
reserved3 = in1.ReadShort();
cellRefs = new CellRangeAddress[cref];
for (int i = 0; i < cellRefs.Length; i++)
{
cellRefs[i] = new CellRangeAddress(in1);
}
switch (isf_sharedFeatureType)
{
case FeatHdrRecord.SHAREDFEATURES_ISFPROTECTION:
sharedFeature = new FeatProtection(in1);
break;
case FeatHdrRecord.SHAREDFEATURES_ISFFEC2:
sharedFeature = new FeatFormulaErr2(in1);
break;
case FeatHdrRecord.SHAREDFEATURES_ISFFACTOID:
sharedFeature = new FeatSmartTag(in1);
break;
default:
System.Console.WriteLine("Unknown Shared Feature " + isf_sharedFeatureType + " found!");
break;
}
}
示例3: CFHeaderRecord
public CFHeaderRecord(CellRangeAddress[] regions, int nRules)
{
CellRangeAddress[] unmergedRanges = regions;
CellRangeAddress[] mergeCellRanges = CellRangeUtil.MergeCellRanges(unmergedRanges);
CellRanges= mergeCellRanges;
field_1_numcf = nRules;
}
示例4: SetArrayFormula
/// <summary>
/// Sets array formula to specified region for result.
/// </summary>
/// <param name="formula">text representation of the formula</param>
/// <param name="range">Region of array formula for result</param>
/// <returns>the <see cref="ICellRange{ICell}"/> of cells affected by this change</returns>
public ICellRange<ICell> SetArrayFormula(String formula, CellRangeAddress range)
{
// make sure the formula parses OK first
int sheetIndex = _workbook.GetSheetIndex(this);
Ptg[] ptgs = HSSFFormulaParser.Parse(formula, _workbook, FormulaType.Array, sheetIndex);
ICellRange<ICell> cells = GetCellRange(range);
foreach (HSSFCell c in cells)
{
c.SetCellArrayFormula(range);
}
HSSFCell mainArrayFormulaCell = (HSSFCell)cells.TopLeftCell;
FormulaRecordAggregate agg = (FormulaRecordAggregate)mainArrayFormulaCell.CellValueRecord;
agg.SetArrayFormula(range, ptgs);
return cells;
}
示例5: MergeCellsRecord
/**
* Constructs a MergedCellsRecord and Sets its fields appropriately
* @param in the RecordInputstream to Read the record from
*/
public MergeCellsRecord(RecordInputStream in1)
{
int nRegions = in1.ReadUShort();
CellRangeAddress[] cras = new CellRangeAddress[nRegions];
for (int i = 0; i < nRegions; i++)
{
cras[i] = new CellRangeAddress(in1);
}
_numberOfRegions = nRegions;
_startIndex = 0;
_regions = cras;
}
示例6: SetBorderLeft
/**
* Sets the left border for a region of cells by manipulating the cell style of the individual
* cells on the left
*
* @param border The new border
* @param region The region that should have the border
* @param workbook The workbook that the region is on.
* @param sheet The sheet that the region is on.
*/
public static void SetBorderLeft(int border, CellRangeAddress region, ISheet sheet,
IWorkbook workbook)
{
int rowStart = region.FirstRow;
int rowEnd = region.LastRow;
int column = region.FirstColumn;
CellPropertySetter cps = new CellPropertySetter(workbook, CellUtil.BORDER_LEFT, border);
for (int i = rowStart; i <= rowEnd; i++)
{
cps.SetProperty(CellUtil.GetRow(i, sheet), column);
}
}
示例7: BuildMergedRangesMap
/**
* Creates a map (i.e. two-dimensional array) filled with ranges. Allow fast
* retrieving {@link CellRangeAddress} of any cell, if cell is contained in
* range.
*
* @see #getMergedRange(CellRangeAddress[][], int, int)
*/
public static CellRangeAddress[][] BuildMergedRangesMap(HSSFSheet sheet)
{
CellRangeAddress[][] mergedRanges = new CellRangeAddress[1][];
for ( int m = 0; m < sheet.NumMergedRegions; m++ )
{
CellRangeAddress cellRangeAddress = sheet.GetMergedRegion( m );
int requiredHeight = cellRangeAddress.LastRow + 1;
if ( mergedRanges.Length < requiredHeight )
{
CellRangeAddress[][] newArray = new CellRangeAddress[requiredHeight][];
Array.Copy( mergedRanges, 0, newArray, 0, mergedRanges.Length );
mergedRanges = newArray;
}
for ( int r = cellRangeAddress.FirstRow; r <= cellRangeAddress.LastRow; r++ )
{
int requiredWidth = cellRangeAddress.LastColumn + 1;
CellRangeAddress[] rowMerged = mergedRanges[r];
if ( rowMerged == null )
{
rowMerged = new CellRangeAddress[requiredWidth];
mergedRanges[r] = rowMerged;
}
else
{
int rowMergedLength = rowMerged.Length;
if ( rowMergedLength < requiredWidth )
{
CellRangeAddress[] newRow = new CellRangeAddress[requiredWidth];
Array.Copy(rowMerged, 0, newRow, 0,rowMergedLength );
mergedRanges[r] = newRow;
rowMerged = newRow;
}
}
//Arrays.Fill( rowMerged, cellRangeAddress.FirstColumn, cellRangeAddress.LastColumn + 1, cellRangeAddress );
for (int i = cellRangeAddress.FirstColumn; i < cellRangeAddress.LastColumn + 1; i++)
{
rowMerged[i] = cellRangeAddress;
}
}
}
return mergedRanges;
}
示例8: CreateSlowestTests
void CreateSlowestTests(int rowNum, IEnumerable<SlowestTest> slowestTests)
{
rowNum = CreateSummaryHeading("20 Slowest Tests", rowNum);
IRow row = sheet.CreateRow(rowNum++);
row.CreateHeadings(ColAssembly, "Assembly", "Class", "Time (secs)", "Time (hh:mm:ss)", "Test Name");
var range = new CellRangeAddress(row.RowNum, row.RowNum, ColPercent, maxColumnUsed);
sheet.AddMergedRegion(range);
foreach (var t in slowestTests)
{
row = sheet.CreateRow(rowNum++);
row.SetCell(ColAssembly, t.AssemblyFileName);
row.SetCell(ColClass, t.ClassName);
row.SetCell(ColTime, t.DurationInSeconds).Format("0.00").ApplyStyle();
row.SetCell(ColTimeHuman, t.DurationHuman).Alignment(HorizontalAlignment.Right).ApplyStyle();
row.SetCell(ColPercent, t.TestName);
range = new CellRangeAddress(row.RowNum, row.RowNum, ColPercent, maxColumnUsed);
sheet.AddMergedRegion(range);
}
}
示例9: SetAutoFilter
/// <summary>
/// Enable filtering for a range of cells
/// </summary>
/// <param name="range">the range of cells to filter</param>
public IAutoFilter SetAutoFilter(CellRangeAddress range)
{
InternalWorkbook workbook = _workbook.Workbook;
int sheetIndex = _workbook.GetSheetIndex(this);
NameRecord name = workbook.GetSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, sheetIndex + 1);
if (name == null)
{
name = workbook.CreateBuiltInName(NameRecord.BUILTIN_FILTER_DB, sheetIndex + 1);
}
int firstRow = range.FirstRow;
// if row was not given when constructing the range...
if (firstRow == -1)
{
firstRow = 0;
}
// The built-in name must consist of a single Area3d Ptg.
Area3DPtg ptg = new Area3DPtg(firstRow, range.LastRow,
range.FirstColumn, range.LastColumn,
false, false, false, false, sheetIndex);
name.NameDefinition = (new Ptg[] { ptg });
AutoFilterInfoRecord r = new AutoFilterInfoRecord();
// the number of columns that have AutoFilter enabled.
int numcols = 1 + range.LastColumn - range.FirstColumn;
r.NumEntries = (short)numcols;
int idx = _sheet.FindFirstRecordLocBySid(DimensionsRecord.sid);
_sheet.Records.Insert(idx, r);
//create a combobox control for each column
HSSFPatriarch p = (HSSFPatriarch)CreateDrawingPatriarch();
for (int col = range.FirstColumn; col <= range.LastColumn; col++)
{
p.CreateComboBox(new HSSFClientAnchor(0, 0, 0, 0,
(short)col, firstRow, (short)(col + 1), firstRow + 1));
}
return new HSSFAutoFilter(this);
}
示例10: IsMergedRegion
/// <summary>
/// Checks if the provided region is part of the merged regions.
/// </summary>
/// <param name="mergedRegion">Region searched in the merged regions</param>
/// <returns><c>true</c>, when the region is contained in at least one of the merged regions</returns>
public bool IsMergedRegion(CellRangeAddress mergedRegion)
{
foreach (CellRangeAddress range in _sheet.MergedRecords.MergedRegions)
{
if (range.FirstColumn <= mergedRegion.FirstColumn
&& range.LastColumn >= mergedRegion.LastColumn
&& range.FirstRow <= mergedRegion.FirstRow
&& range.LastRow >= mergedRegion.LastRow)
{
return true;
}
}
return false;
}
示例11: SetBorderBottomOfRegion
/// <summary>
/// Sets the bottom border of region.
/// </summary>
/// <param name="region">The region.</param>
/// <param name="borderType">Type of the border.</param>
/// <param name="color">The color.</param>
public void SetBorderBottomOfRegion(CellRangeAddress region, NPOI.SS.UserModel.BorderStyle borderType, short color)
{
HSSFRegionUtil.SetBottomBorderColor(color, region, this, _workbook);
HSSFRegionUtil.SetBorderBottom(borderType, region, this, _workbook);
}
示例12: GetCellRange
/// <summary>
/// Also creates cells if they don't exist.
/// </summary>
private ICellRange<ICell> GetCellRange(CellRangeAddress range)
{
int firstRow = range.FirstRow;
int firstColumn = range.FirstColumn;
int lastRow = range.LastRow;
int lastColumn = range.LastColumn;
int height = lastRow - firstRow + 1;
int width = lastColumn - firstColumn + 1;
List<ICell> temp = new List<ICell>(height * width);
for (int rowIn = firstRow; rowIn <= lastRow; rowIn++)
{
for (int colIn = firstColumn; colIn <= lastColumn; colIn++)
{
IRow row = GetRow(rowIn);
if (row == null)
{
row = CreateRow(rowIn);
}
ICell cell = row.GetCell(colIn);
if (cell == null)
{
cell = row.CreateCell(colIn);
}
temp.Add(cell);
}
}
return SSCellRange<ICell>.Create(firstRow, firstColumn, height, width, temp, typeof(HSSFCell));
}
示例13: MergeCell
public void MergeCell(int x1,int y1,int x2,int y2)
{
CellRangeAddress range = new CellRangeAddress(y1, y2, x1, x2);
sheet.AddMergedRegion(range);
}
示例14: SetEnclosedBorderOfRegion
/// <summary>
/// Sets the enclosed border of region.
/// </summary>
/// <param name="region">The region.</param>
/// <param name="borderType">Type of the border.</param>
/// <param name="color">The color.</param>
public void SetEnclosedBorderOfRegion(CellRangeAddress region, NPOI.SS.UserModel.BorderStyle borderType, short color)
{
HSSFRegionUtil.SetRightBorderColor(color, region, this, _workbook);
HSSFRegionUtil.SetBorderRight(borderType, region, this, _workbook);
HSSFRegionUtil.SetLeftBorderColor(color, region, this, _workbook);
HSSFRegionUtil.SetBorderLeft(borderType, region, this, _workbook);
HSSFRegionUtil.SetTopBorderColor(color, region, this, _workbook);
HSSFRegionUtil.SetBorderTop(borderType, region, this, _workbook);
HSSFRegionUtil.SetBottomBorderColor(color, region, this, _workbook);
HSSFRegionUtil.SetBorderBottom(borderType, region, this, _workbook);
}
示例15: SetRepeatingRowsAndColumns
private void SetRepeatingRowsAndColumns(
CellRangeAddress rowDef, CellRangeAddress colDef)
{
int sheetIndex = _workbook.GetSheetIndex(this);
int maxRowIndex = SpreadsheetVersion.EXCEL97.LastRowIndex;
int maxColIndex = SpreadsheetVersion.EXCEL97.LastColumnIndex;
int col1 = -1;
int col2 = -1;
int row1 = -1;
int row2 = -1;
if (rowDef != null)
{
row1 = rowDef.FirstRow;
row2 = rowDef.LastRow;
if ((row1 == -1 && row2 != -1) || (row1 > row2)
|| (row1 < 0 || row1 > maxRowIndex)
|| (row2 < 0 || row2 > maxRowIndex))
{
throw new ArgumentException("Invalid row range specification");
}
}
if (colDef != null)
{
col1 = colDef.FirstColumn;
col2 = colDef.LastColumn;
if ((col1 == -1 && col2 != -1) || (col1 > col2)
|| (col1 < 0 || col1 > maxColIndex)
|| (col2 < 0 || col2 > maxColIndex))
{
throw new ArgumentException("Invalid column range specification");
}
}
short externSheetIndex =
(short)_workbook.Workbook.CheckExternSheet(sheetIndex);
bool setBoth = rowDef != null && colDef != null;
bool removeAll = rowDef == null && colDef == null;
HSSFName name = _workbook.GetBuiltInName(NameRecord.BUILTIN_PRINT_TITLE, sheetIndex);
if (removeAll)
{
if (name != null)
{
_workbook.RemoveName(name);
}
return;
}
if (name == null)
{
name = _workbook.CreateBuiltInName(
NameRecord.BUILTIN_PRINT_TITLE, sheetIndex);
}
List<Ptg> ptgList = new List<Ptg>();
if (setBoth)
{
int exprsSize = 2 * 11 + 1; // 2 * Area3DPtg.SIZE + UnionPtg.SIZE
ptgList.Add(new MemFuncPtg(exprsSize));
}
if (colDef != null)
{
Area3DPtg colArea = new Area3DPtg(0, maxRowIndex, col1, col2,
false, false, false, false, externSheetIndex);
ptgList.Add(colArea);
}
if (rowDef != null)
{
Area3DPtg rowArea = new Area3DPtg(row1, row2, 0, maxColIndex,
false, false, false, false, externSheetIndex);
ptgList.Add(rowArea);
}
if (setBoth)
{
ptgList.Add(UnionPtg.instance);
}
Ptg[] ptgs = ptgList.ToArray();
//ptgList.toArray(ptgs);
name.SetNameDefinition(ptgs);
HSSFPrintSetup printSetup = (HSSFPrintSetup)PrintSetup;
printSetup.ValidSettings = (false);
SetActive(true);
}