当前位置: 首页>>代码示例>>C#>>正文


C# Range.get_Resize方法代码示例

本文整理汇总了C#中Microsoft.Office.Interop.Excel.Range.get_Resize方法的典型用法代码示例。如果您正苦于以下问题:C# Range.get_Resize方法的具体用法?C# Range.get_Resize怎么用?C# Range.get_Resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Office.Interop.Excel.Range的用法示例。


在下文中一共展示了Range.get_Resize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HttpsCompleted

        private void HttpsCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                string response = e.Result;
                DataTable xmlData = Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>(response);
                //DataTable dtObj = new DataTable("MyExcel");
                try
                {
                    activeWorksheet.UsedRange.ClearContents();
                    foreach (DataColumn cols in xmlData.Columns)
                    {
                        newFirstRow.Value2 = cols.ColumnName;
                        newFirstRow = newFirstRow.Next;
                    }
                    newFirstRow = activeWorksheet.Cells[firstRow.Row + 1, firstRow.Column];
                    object[] data = new object[xmlData.Columns.Count];
                    foreach (DataRow dr in xmlData.Rows)
                    {
                        data = new object[xmlData.Columns.Count];
                        data = dr.ItemArray;

                        //= (Excel.Range)activeWorksheet.Cells[newFirstRow.Row, firstRow.Column]; ;
                        Excel.Range newRangeData = newFirstRow.get_Resize(1, xmlData.Columns.Count);

                        newRangeData.set_Value(Type.Missing, data);
                        newFirstRow = activeWorksheet.Cells[newFirstRow.Row + 1, firstRow.Column];
                    }
                    firstRow.get_Offset(1, 1).get_Resize(xmlData.Rows.Count, xmlData.Columns.Count).Style = "Currency";
                }
                catch(Exception ex)
                {
                    firstRow.Value2 = "An Error occured while performing operation on the excel";
                }
            }
            else
            {
                firstRow.Value2 = "An Error occured while accessing the service";
            }
        }
开发者ID:ronyd1,项目名称:exceladdin,代码行数:40,代码来源:RibbonFetch.cs

示例2: AddInfo

        public void AddInfo(FunctionTableItem[] fun, ValueIs value = ValueIs.Magnitude, bool addChart = false)
        {
            Excel.Series series;
            Excel.Range temp;

            range = range.get_Resize(2, fun.Length);
            range.set_Value(Missing.Value, GetArray(fun, value));

            if (addChart)
            {
                LastIndex += chartHeight + 10;
                chartObject = charts.Add(400, LastIndex, chartWidth, chartHeight);
            }
            currentChart = chartObject.Chart;
            series = ((Excel.SeriesCollection) currentChart.SeriesCollection(Type.Missing)).NewSeries();
            temp = range.get_Resize(1, fun.Length);
            series.Values = temp;
            series.XValues = temp.get_Offset(1, 0);
            currentChart.ChartType = Excel.XlChartType.xlXYScatterSmoothNoMarkers;

            range = range.get_Offset(3, 0);
        }
开发者ID:FarrelLabs,项目名称:lab1,代码行数:22,代码来源:ReportBuilder.cs

示例3: AddExcelRows

 /// <summary>
 /// 将数据填充到Excel工作表的单元格中
 /// </summary>
 /// <param name="startRange"></param>
 /// <param name="rowCount"></param>
 /// <param name="colCount"></param>
 /// <param name="values"></param>
 private void AddExcelRows(string startRange, int rowCount, int colCount, object values)
 {
     _range = _sheet.get_Range(startRange, _optionalValue);
     _range = _range.get_Resize(rowCount, colCount);
     _range.set_Value(_optionalValue, values);
 }
开发者ID:wybq68,项目名称:DIH_LUMBARROBAT,代码行数:13,代码来源:ExcelHelper.cs

示例4: AutoFitColumns

 private void AutoFitColumns(string startRange, int rowCount, int colCount)
 {
     _range = _sheet.get_Range(startRange, _optionalValue);
     _range = _range.get_Resize(rowCount, colCount);
     _range.Columns.AutoFit();
 }
开发者ID:wybq68,项目名称:DIH_LUMBARROBAT,代码行数:6,代码来源:ExcelHelper.cs

示例5: DataTableToExcel

        /// <summary>
        /// 将DataTable数据写入Excel文件(自动分页,并指定要合并的列索引)
        /// </summary>
        /// <param name="dt">DataTable</param>
        /// <param name="rows">每个WorkSheet写入多少行数据</param>
        /// <param name="top">表格数据起始行索引</param>
        /// <param name="left">表格数据起始列索引</param>
        /// <param name="mergeColumnIndex">DataTable中要合并相同行的列索引,从0开始</param>
        public void DataTableToExcel(DataTable dt, int rows, int top, int left, int mergeColumnIndex)
        {
            int rowCount = dt.Rows.Count;  //源DataTable行数
            int colCount = dt.Columns.Count; //源DataTable列数
            sheetCount = this.GetSheetCount(rowCount, rows); //WorkSheet个数
            //   StringBuilder sb;

            //复制sheetCount-1个WorkSheet对象
            for (int i = 1; i < sheetCount; i++)
            {
                workSheet = (Excel.Worksheet)workBook.Worksheets.get_Item(i);
                workSheet.Copy(missing, workBook.Worksheets[i]);
            }

            for (int i = 1; i <= sheetCount; i++)
            {
                int startRow = (i - 1) * rows;  //记录起始行索引
                int endRow = i * rows;   //记录结束行索引

                //若是最后一个WorkSheet,那么记录结束行索引为源DataTable行数
                if (i == sheetCount)
                    endRow = rowCount;

                //获取要写入数据的WorkSheet对象,并重命名
                workSheet = (Excel.Worksheet)workBook.Worksheets.get_Item(i);
                workSheet.Name = sheetPrefixName + "-" + i.ToString();

                //将dt中的数据写入WorkSheet
                //    for(int j=0;j<endRow-startRow;j++)
                //    {
                //     for(int k=0;k<colCount;k++)
                //     {
                //      workSheet.Cells[top + j,left + k] = dt.Rows[startRow + j][k].ToString();
                //     }
                //    }

                //利用二维数组批量写入
                int row = endRow - startRow;
                string[,] ss = new string[row, colCount];

                for (int j = 0; j < row; j++)
                {
                    for (int k = 0; k < colCount; k++)
                    {
                        ss[j, k] = dt.Rows[startRow + j][k].ToString();
                    }
                }

                range = (Excel.Range)workSheet.Cells[top, left];
                range = range.get_Resize(row, colCount);
                range.Value = ss;

                //合并相同行
                this.MergeRows(workSheet, left + mergeColumnIndex, top, rows);

            }
        }
开发者ID:ramic,项目名称:ramic,代码行数:65,代码来源:ExcelBase.cs

示例6: ArrayToExcel

        /// <summary>
        /// 将二维数组数据写入Excel文件(自动分页,并指定要合并的列索引)
        /// </summary>
        /// <param name="arr">二维数组</param>
        /// <param name="rows">每个WorkSheet写入多少行数据</param>
        /// <param name="top">行索引</param>
        /// <param name="left">列索引</param>
        /// <param name="mergeColumnIndex">数组的二维索引,相当于DataTable的列索引,索引从0开始</param>
        public void ArrayToExcel(string[,] arr, int rows, int top, int left, int mergeColumnIndex)
        {
            int rowCount = arr.GetLength(0);  //二维数组行数(一维长度)
            int colCount = arr.GetLength(1); //二维数据列数(二维长度)
            sheetCount = this.GetSheetCount(rowCount, rows); //WorkSheet个数

            //复制sheetCount-1个WorkSheet对象
            for (int i = 1; i < sheetCount; i++)
            {
                workSheet = (Excel.Worksheet)workBook.Worksheets.get_Item(i);
                workSheet.Copy(missing, workBook.Worksheets[i]);
            }

            //将二维数组数据写入Excel
            for (int i = sheetCount; i >= 1; i--)
            {
                int startRow = (i - 1) * rows;  //记录起始行索引
                int endRow = i * rows;   //记录结束行索引

                //若是最后一个WorkSheet,那么记录结束行索引为源DataTable行数
                if (i == sheetCount)
                    endRow = rowCount;

                //获取要写入数据的WorkSheet对象,并重命名
                workSheet = (Excel.Worksheet)workBook.Worksheets.get_Item(i);
                workSheet.Name = sheetPrefixName + "-" + i.ToString();

                //将二维数组中的数据写入WorkSheet
                for (int j = 0; j < endRow - startRow; j++)
                {
                    for (int k = 0; k < colCount; k++)
                    {
                        workSheet.Cells[top + j, left + k] = arr[startRow + j, k];
                    }
                }

                //利用二维数组批量写入
                int row = endRow - startRow;
                string[,] ss = new string[row, colCount];

                for (int j = 0; j < row; j++)
                {
                    for (int k = 0; k < colCount; k++)
                    {
                        ss[j, k] = arr[startRow + j, k];
                    }
                }

                range = (Excel.Range)workSheet.Cells[top, left];
                range = range.get_Resize(row, colCount);
                range.Value = ss;

                //合并相同行
                this.MergeRows(workSheet, left + mergeColumnIndex, top, rows);
            }
        }
开发者ID:ramic,项目名称:ramic,代码行数:64,代码来源:ExcelBase.cs


注:本文中的Microsoft.Office.Interop.Excel.Range.get_Resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。