views:

1321

answers:

2

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.

A: 

Please look at

http://support.microsoft.com/kb/306572

and

http://support.microsoft.com/kb/306023/EN-US/

You can implement your idea..

lakshmanaraj
how can i unmerge cells if they are merged in whole worksheet?
Ibrahim AKGUN
+1  A: 
  1. Download and install Office 2003 Primary Interop Assemblies on your computer
  2. Create a Visual studio Project and add a reference to 'Microsoft.Office.Interop.Excel.dll' from the GAC.
  3. 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);
    

    }

Frederick
i will give a try for this.But this is not control if B1 B2 B3 .... is Numeric or Null..If they are null or is not numeric it will get next row.If ya want i can send my template excel file and non edited excel file.
Ibrahim AKGUN