如何获取 excel 工作簿中的第一行并使用 .net c# 将其保存到新的 excel 工作簿中?我不知道列的数量,所以需要获取整行。这是我所拥有的,但新工作簿是空白的(没有复制行)
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(file);
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRangeHeader = xlWorksheet.get_Range("A1", "A1").EntireRow;
Excel.Workbook xlWorkbookNew = xlApp.Workbooks.Add();
Excel._Worksheet xlWorksheetNew = xlWorkbookNew.Sheets[1];
xlWorksheetNew.get_Range("A1", "A1").EntireRow.Value = xlRangeHeader;
xlWorkbook.Close(false);
xlWorkbookNew.SaveAs(Path.Combine(sDestination, Path.GetFileName(file)), fileFormat);
xlWorkbookNew.Close(true);