public void WriteCell(ReportSheetTemplate tpl, GroupDataHolder holder, CellRange currentCellRange, DataTable table, int valueRowIndex) { if (useR1C1Formula) { currentCellRange.FormulaR1C1 = "=" + tplTextContent; return; // do noting } object value = GetValue(holder, table, valueRowIndex); if (value == null || value == string.Empty || value == System.DBNull.Value) { value = tplDefaultContent; } // update value. RangeHelper.UpdateCellValue(tpl, currentCellRange, value, tplFormat); if (align == GroupAlign.vGroup) { lastGroupedValue = GetGroupValue(holder, table, valueRowIndex); } lastCellRange = currentCellRange; }
public void FillTemplate() { for (int i = 0; i < blockList.Count; i++) { TplBlock block = blockList [i]; if (block.copyOnly) { Range range = RangeHelper.InsertCopyRange(sheet, block.tplRange, block.tplColumCount, block.tplRowCount, block.startColIndex, startRowIndex + rowCount, XlInsertShiftDirection.xlShiftDown); IEnumerator e = RangeHelper.GetRangeCells(range); while (e.MoveNext()) { Range cell = (Range)e.Current; if (cell.HasMerged) { continue; } string s = cell.Value2 as string; if (s != null && s.StartsWith("#") && s.Length > 1 && paramMap != null) { s = s.Substring(1); string[] s2 = s.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); object pValue = null; paramMap.TryGetValue(s2 [0], out pValue); string format = ""; if (s2.Length > 1) { format = s2 [1].ToLower(); } RangeHelper.UpdateCellValue(this, cell, pValue, format); } CellRange origin = RangeHelper.GetRange(sheet, cell.Column, cell.Row - startRowIndex - rowCount + block.startRowIndex, 1, 1); if (origin.HasMerged) { // doMerge int col = origin.MergeArea.Column; int mWidth = origin.MergeArea.ColumnCount; int row = origin.MergeArea.Row + startRowIndex + rowCount - block.startRowIndex; int mHeight = origin.MergeArea.RowCount; CellRange mRange = RangeHelper.GetRange(sheet, col, row, mWidth, mHeight); if (!mRange.HasMerged) { mRange.Merge(); } } } rowCount += block.tplRowCount; } else { block.startRowIndex = startRowIndex + rowCount; if (block.isChart) { // chart block should be filled at last. return; } // check cloumn table first if (!string.IsNullOrEmpty(block.tplColTableName) && dset.Tables.Contains(block.tplColTableName)) { block.CreateDColumns(dset.Tables [block.tplColTableName]); } if (!dset.Tables.Contains(block.tableName)) { throw new ArgumentException("DataTable [" + block.tableName + "] of Block [" + block.name + "] not found in DataSet!"); } if (dset.Tables[block.tableName].Rows.Count <= 0 && block.emptyTableName != null) { rowCount += block.FillBlock(dset.Tables[block.emptyTableName]); } else { rowCount += block.FillBlock(dset.Tables [block.tableName]); } } } }