this code is searching and getting data from excelfileSource and save it in a second excelfileDestination ;; I want to convert this code from using spire.xls to normal Excel.App method .
this is my code using Spire.xls :
public void myCodeSpire ()
{
workbook newBook = new Workbook();
newBook.LoadFromFile("ExcelFileDestination.xls", ExcelVersion.Version97to2003);
Worksheet newSheet = newBook.Worksheets[0];
Workbook workbook = new Workbook();
workbook.LoadFromFile(ExcelFileSource.xls, ExcelVersion.Version97to2003);
Worksheet sheet = workbook.Worksheets[2];
foreach (CellRange range in sheet.Columns[0])
{
if (range.Text == KeySearch)
{
CellRange sourceRange = sheet.Range[range.Row, 5, range.Row + 2, 7];
CellRange destRange = newSheet.Range[34, 3, 36, 5];
sheet.Copy(sourceRange, destRange,true);
sourceRange = sheet.Range[range.Row, 9, range.Row + 2, 11];
destRange = newSheet.Range[34, 6, 36, 8];
sheet.Copy(sourceRange, destRange, true);
sourceRange = sheet.Range[range.Row, 13, range.Row + 2, 13];
destRange = newSheet.Range[34, 9, 36, 9];
sheet.Copy(sourceRange, destRange, true);
sourceRange = sheet.Range[range.Row, 15, range.Row + 2, 15];
destRange = newSheet.Range[34, 10, 36, 10];
sheet.Copy(sourceRange, destRange, true);
}
}
newSheet.Range["C34:J36"].NumberFormat = "0.000";
newSheet.Range["C34:J36"].Borders.LineStyle = LineStyleType.Thin;
newSheet.Range["C34:J36"].Borders.Color =System.Drawing.Color.Black;
newSheet.Range["C34:J36"].Border[BordersLineType.DiagonalDown].LineStyle= LineStyleType.None;
newSheet.Range["C34:J36"].Borders[BordersLineType.DiagonalUp].LineStyle = LineStyleType.None;
newBook.SaveToFile("ExcelFileDestination.xls", ExcelVersion.Version97to2003);
}
Thank you for any help .
What I have tried:
public void myCodeExcel.Appli()
{
Excel.Application APP = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook newBook = APP.Workbooks.Open(excelFileDestinationPAth);
Microsoft.Office.Interop.Excel.Worksheet newSheet = (Microsoft.Office.Interop.Excel.Worksheet) newBook.Worksheets[1];
Microsoft.Office.Interop.Excel.Workbook workBook = APP.Workbooks.Open(excelFileSourcePAth);
Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet) workbook.Worksheets[3];
foreach (CellRange range in sheet.Columns[0])
{
if (range.Text == KEYsearch)
{
}
newBook.save(excelFileDestinationPath);