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


C# Range.Copy方法代码示例

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


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

示例1: CopyRows

        /// <summary>
        /// 复制行(在指定WorkSheet指定行下面复制指定数量行)
        /// </summary>
        /// <param name="sheetIndex"></param>
        /// <param name="rowIndex"></param>
        /// <param name="count"></param>
        public void CopyRows(int sheetIndex, int rowIndex, int count)
        {
            if (sheetIndex > this.WorkSheetCount)
            {
                this.KillExcelProcess();
                throw new Exception("索引超出范围,WorkSheet索引不能大于WorkSheet数量!");
            }

            try
            {
                workSheet = (Excel.Worksheet)workBook.Worksheets[sheetIndex];
                range1 = (Excel.Range)workSheet.Rows[rowIndex, this.missing];

                for (int i = 1; i <= count; i++)
                {
                    range2 = (Excel.Range)workSheet.Rows[rowIndex + i, this.missing];
                    range1.Copy(range2);
                }
            }
            catch (Exception e)
            {
                this.KillExcelProcess();
                throw e;
            }
        }
开发者ID:ramic,项目名称:ramic,代码行数:31,代码来源:ExcelBase.cs

示例2: copyCells

 /// <summary>
 /// ћетод копирует выбранный диапазон ¤чеек на новое место
 /// </summary>
 /// <param name="start">Ћева¤ верхн¤¤ ¤чейка диапазона</param>
 /// <param name="end">ѕрава¤ нижн¤¤ ¤чейка диапазона</param>
 /// <param name="destination">ячейка нового местоположени¤</param>
 public void copyCells(object start, object end, object destination)
 {
     Excel.Range rangeDest = xlWorkSheet.get_Range(destination, misValue);
         range = xlWorkSheet.get_Range(start, end);
         range.Copy(rangeDest);
 }
开发者ID:Blyumenshteyn,项目名称:UchetUSP,代码行数:12,代码来源:ExcelClass.cs

示例3: CopyColumns

        /// <summary>
        /// 复制列(在指定WorkSheet指定列右边复制指定数量列)
        /// </summary>
        /// <param name="sheetIndex"></param>
        /// <param name="columnIndex"></param>
        /// <param name="count"></param>
        public void CopyColumns(int sheetIndex, int columnIndex, int count)
        {
            if (sheetIndex > this.WorkSheetCount)
            {
                this.KillExcelProcess();
                throw new Exception("索引超出范围,WorkSheet索引不能大于WorkSheet数量!");
            }

            try
            {
                workSheet = (Excel.Worksheet)workBook.Worksheets[sheetIndex];
                //    range1 = (Excel.Range)workSheet.Columns[Type.Missing,columnIndex];
                range1 = (Excel.Range)workSheet.get_Range(this.IntToLetter(columnIndex) + "1", this.IntToLetter(columnIndex) + "10000");

                for (int i = 1; i <= count; i++)
                {
                    //     range2 = (Excel.Range)workSheet.Columns[Type.Missing,columnIndex + i];
                    range2 = (Excel.Range)workSheet.get_Range(this.IntToLetter(columnIndex + i) + "1", this.IntToLetter(columnIndex + i) + "10000");
                    range1.Copy(range2);
                }
            }
            catch (Exception e)
            {
                this.KillExcelProcess();
                throw e;
            }
        }
开发者ID:ramic,项目名称:ramic,代码行数:33,代码来源:ExcelBase.cs

示例4: RangeCopy

        /// <summary>
        /// 将指定范围区域拷贝到目标区域
        /// </summary>
        /// <param name="sheetName">WorkSheet名称</param>
        /// <param name="startCell">要拷贝区域的开始Cell位置(比如:A10)</param>
        /// <param name="endCell">要拷贝区域的结束Cell位置(比如:F20)</param>
        /// <param name="targetCell">目标区域的开始Cell位置(比如:H10)</param>
        public void RangeCopy(string sheetName, string startCell, string endCell, string targetCell)
        {
            try
            {
                Excel.Worksheet sheet = null;

                for (int i = 1; i <= this.WorkSheetCount; i++)
                {
                    workSheet = (Excel.Worksheet)workBook.Sheets.get_Item(i);

                    if (workSheet.Name == sheetName)
                    {
                        sheet = workSheet;
                    }
                }

                if (sheet != null)
                {
                    for (int i = sheetCount; i >= 1; i--)
                    {
                        range1 = sheet.get_Range(startCell, endCell);
                        range2 = sheet.get_Range(targetCell, this.missing);

                        range1.Copy(range2);
                    }
                }
                else
                {
                    this.KillExcelProcess();
                    throw new Exception("名称为\"" + sheetName + "\"的工作表不存在");
                }
            }
            catch (Exception e)
            {
                this.KillExcelProcess();
                throw e;
            }
        }
开发者ID:ramic,项目名称:ramic,代码行数:45,代码来源:ExcelBase.cs

示例5: CopyCells

 /// <summary>
 /// Метод копирует выбранный диапазон ячеек на новое место
 /// </summary>
 /// <param name="start">Левая верхняя ячейка диапазона</param>
 /// <param name="end">Правая нижняя ячейка диапазона</param>
 /// <param name="destination">Ячейка нового местоположения</param>
 public void CopyCells(object start, object end, object destination)
 {
     Excel.Range rangeDest = _xlWorkSheet.Range[destination, _misValue];
     _range = _xlWorkSheet.Range[start, end];
     _range.Copy(rangeDest);
 }
开发者ID:IgorGorbunov,项目名称:SmartLabParser,代码行数:12,代码来源:ExcelClass.cs

示例6: CopyRows

 /// <summary>
 /// 复制行(在指定行下面复制指定数量行)
 /// </summary>
 /// <param name="rowIndex"></param>
 /// <param name="count"></param>
 public void CopyRows(int rowIndex, int count)
 {
     try
     {
         range1 = (Excel.Range)workSheet.Rows[rowIndex, this.missing];
         for (int i = 1; i <= count; i++)
         {
             range2 = (Excel.Range)workSheet.Rows[rowIndex + i, this.missing];
             range1.Copy(range2);
         }
     }
     catch (Exception e)
     {
         this.KillExcelProcess(false);
         throw e;
     }
 }
开发者ID:linyc,项目名称:CTool,代码行数:22,代码来源:CExcel.cs


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