I wanna to read some excel files and convert to my own excel template.I want to read B coloumn every line.(B1,B2,B3... going like this.) If there is a number in this coloumn ; in B3 there is number like "1,2,3,4,5,6,7,8,9"than i ll get this whole line and take it to an array[i].If there is "5" number in B4 than it ll get this whole line and take it to an array[i] .If there is no number in related line it will contiune to next line.It will contiune to read end of the excel file.And i wanna take this array and write to a new excel file.Thats what i want please help me with example codes.
Please look at
http://support.microsoft.com/kb/306572
and
http://support.microsoft.com/kb/306023/EN-US/
You can implement your idea..
- Download and install Office 2003 Primary Interop Assemblies on your computer
- Create a Visual studio Project and add a reference to 'Microsoft.Office.Interop.Excel.dll' from the GAC.
Now you can write this code to read data from any Excelfile:
using Excel = Microsoft.Office.Interop.Excel;
string pathOfExcelFile = "C:\\MyDataFile.xls";
Excel.Application excelApp = new Excel.Application();
excelApp.DisplayAlerts = false; //Don't want Excel to display error messageboxes
Excel.Workbook workbook = excelApp.Workbooks.Open(pathOfExcelFile, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); //This opens the file
Excel.Worksheet sheet = workbook.get_Item(1); //Get the first sheet in the file Excel.Range bColumn = sheet.get_Range("B", null);
List<string> dataItems = new List<string>();
foreach (object o in bColumn)
{Excel.Range row = o as Excel.Range; string s = row.get_Value(null); dataItems.Add(s);
}