Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用gembox电子表格在Excel中复制和插入特定行_C#_Excel_Copy_Row_Gembox Spreadsheet - Fatal编程技术网

C# 如何使用gembox电子表格在Excel中复制和插入特定行

C# 如何使用gembox电子表格在Excel中复制和插入特定行,c#,excel,copy,row,gembox-spreadsheet,C#,Excel,Copy,Row,Gembox Spreadsheet,请帮忙。我使用gembox.spreadsheet库在excel文件的2张图纸中插入和复制特定行。 但它仍然有无效论点的问题 public void InsertCopyData() { SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY"); ExcelFile ef = new ExcelFile(); // Loads Excel file. ef.LoadXls(@"C:\templateExcel\DataTabl

请帮忙。我使用gembox.spreadsheet库在excel文件的2张图纸中插入和复制特定行。 但它仍然有无效论点的问题

public void InsertCopyData()
{
    SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
    ExcelFile ef = new ExcelFile();

    // Loads Excel file.
    ef.LoadXls(@"C:\templateExcel\DataTable.xls");

    // Selects first and 2nd worksheet.
    ExcelWorksheet w1 = ef.Worksheets[0];
    ExcelWorksheet w2 = ef.Worksheets[1];

    //insert copy file  
    w1.InsertCopy(w1.Rows["A1"], w2.Rows["A4"]);


    //Saves the file in XLS format.
    ef.SaveXls(@"C:\templateExcel\Insert DataTable.xls");
}

不能这样使用:
ef.LoadXls(@“C:\templateExcel\DataTable.xls”)

您应该写入以加载现有Excel文件

GemBox.Spreadsheet.ExcelFile ef = new GemBox.Spreadsheet.ExcelFile();
ef = GemBox.Spreadsheet.**ExcelFile.Load**("D:\\Example.xlsx");
ExcelWorksheet ws = ef.Worksheets["Sheet1"];  (or)   ExcelWorksheet ws = ef.Worksheets[0]; 
// writing data to excel file code...
ws.Cells[0, 0].Value = example_1;
ws.Cells[1, 0].Value = example_2;
ef.Save("D:\\Example.xlsx");

请注意,GemBox.Spreadsheet可以让您插入工作表、行和/或列。 与无效参数一起使用的API用于插入工作表副本,要插入行副本,请使用以下方法:

// Inserts specified number of copied rows before the current row.
var currentRow = w1.Rows["A1"];
currentRow.InsertCopy(1, w2.Rows["A4"]);

这是可行的,但会导致两个问题:a。ArgumentOutOfRangeException-调用GetUsedCellRange(true)b时,行索引不能大于最大行索引(1048575)。Excel 2013显示了一条警告“我们发现某些内容存在问题”,我恐怕需要调查您的输入和输出Excel文件,以便准确地告诉您问题所在。您应该提交一份支持票,并提供一些信息(或文件),我们将能够复制您的问题。