private void AddCalculations(Excel.PivotTable pivotTable) { // 获取构成数据透视表的范围。 Excel.Range tableRange = pivotTable.TableRange1; Excel.Range dataRange = pivotTable.DataBodyRange; // 获取需要添加到数据透视表后面的 // 每个列。 System.Array values = Enum.GetValues(typeof(StatHeadings)); // 确定数据透视表的左上角单元格。 Excel.Range tableStartCell = ExcelHelpers.GetCellFromRange(tableRange, 1, 1); // 获取数据透视表末尾相应行中的 // 第一个可用单元格。 Excel.Range nextHeader = tableStartCell.get_End(Excel.XlDirection.xlDown).get_End(Excel.XlDirection.xlToRight).get_End(Excel.XlDirection.xlUp).Next; // 确定构成当前列的计算字段的 // 边界单元格。 Excel.Range colStart = ExcelHelpers.GetCellFromRange(nextHeader, 2, 1); Excel.Range colEnd = colStart.get_Offset(dataRange.Rows.Count - 1, 0); // 对于需要添加的每一列, // 填充其统计信息和标题。 foreach (int i in values) { nextHeader.Value2 = this.headers[i]; this.PopulateStatColumn(i, colStart, colEnd); nextHeader = nextHeader.Next; colStart = colStart.Next; colEnd = colEnd.Next; } }
private void AddCalculations(Excel.PivotTable pivotTable) { // Gets the ranges that make up the PivotTable. Excel.Range tableRange = pivotTable.TableRange1; Excel.Range dataRange = pivotTable.DataBodyRange; // Gets each of the columns that needs to be added after the // PivotTable. System.Array values = Enum.GetValues(typeof(StatHeadings)); // Determines upper left cell of the PivotTable. Excel.Range tableStartCell = ExcelHelpers.GetCellFromRange(tableRange, 1, 1); // Gets the first available cell in the appropriate row at the // end of the PivotTable. Excel.Range nextHeader = tableStartCell.get_End(Excel.XlDirection.xlDown).get_End(Excel.XlDirection.xlToRight).get_End(Excel.XlDirection.xlUp).Next; // Determines the boundary cells that make up the calculated fields // for the current column. Excel.Range colStart = ExcelHelpers.GetCellFromRange(nextHeader, 2, 1); Excel.Range colEnd = colStart.get_Offset(dataRange.Rows.Count - 1, 0); // For each of the columns that need to be added, // populates its stats and headings. foreach (int i in values) { nextHeader.Value2 = this.headers[i]; this.PopulateStatColumn(i, colStart, colEnd); nextHeader = nextHeader.Next; colStart = colStart.Next; colEnd = colEnd.Next; } }
private void PopulateDateInformation(DateTime selectedDate) { // 此方法用下一个订货日期及其相应的 // 交货日期来填充工作表。 // 获取下一个订货日期并填充该日期。 Excel.Range orderDateCell = worksheet.get_Range(orderDateAddress, defaultParameter); orderDateCell.Value2 = Properties.Resources.OrderDateHeader; orderDateCell.Next.Value2 = selectedDate.ToShortDateString(); Excel.Range deliveryDateCell = ExcelHelpers.GetCellFromRange(orderDateCell, 2, 1); deliveryDateCell.Value2 = Properties.Resources.DeliveryDateHeader; deliveryDateCell.Next.Value2 = this.deliveryDate.ToShortDateString(); }
private void PopulateDateInformation(DateTime selectedDate) { // This method populates the worksheet with the next order // date and its corresponding delivery date. // Gets the next order date and populates it. Excel.Range orderDateCell = worksheet.get_Range(orderDateAddress, defaultParameter); orderDateCell.Value2 = Properties.Resources.OrderDateHeader; orderDateCell.Next.Value2 = selectedDate.ToShortDateString(); Excel.Range deliveryDateCell = ExcelHelpers.GetCellFromRange(orderDateCell, 2, 1); deliveryDateCell.Value2 = Properties.Resources.DeliveryDateHeader; deliveryDateCell.Next.Value2 = this.deliveryDate.ToShortDateString(); }