本文整理汇总了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;
}
}
示例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);
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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;
}
}