My code is about Retrieving data and extract to the first worksheet of the new excel workbook ,
I'm using here wpf ,and the spire.xls method :
I tried to find something seemlier but i couldn't debug my code .
Ps: cellRAnge is available only when i use spire.xls
I want to replace spire.xls use with Excel.APP
using Spire.Xls;
public void codespire()
{
Workbook newBook = new Workbook();
Worksheet newSheet = newBook.Worksheets[0];
Workbook workbook = new Workbook();
workbook.LoadFromFile("Information.xlsx");
Worksheet sheet = workbook.Worksheets[0];
int i = 1;
int columnCount = sheet.Columns.Count();
foreach (CellRange range in sheet.Columns[0])
{
if (range.Text == "teacher")
{
CellRange sourceRange = sheet.Range[range.Row, 1, range.Row, columnCount];
CellRange destRange = newSheet.Range[i, 1, i, columnCount];
sheet.Copy(sourceRange, destRange, true);
i++;
}
}
newBook.SaveToFile("NewForm.xlsx", ExcelVersion.Version2010);
}
}
}
What I have tried:
I want to replace spire.xls with with Excel.APPlication methode:
using Excel = Microsoft.Office.Interop.Excel;
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[1];
int i =1 ;
int columnCount = sheet.Columns.Count();
foreach (Excel.Range r in (Excel.Range) sheet.Columns["A", Type.Missing])
{
Excel.Range rang = r.Find(numSérie,sheet.Cells[i, 1],Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext,
false,false,false);
string cellAdress = rang.get_Address(false, false, Excel.XlReferenceStyle.xlA1, false, false);
string rangeCellSearch = sheet.Range[cellAdress].Value;
if (rangeCellSearch == Teacher)
{
}