View Single Post
Join Date: Oct 2008
Posts: 2,721
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 498
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: opening Excel 2003 file by c#

 
0
  #6
May 20th, 2009
Hi!
Hope this code will resolve your problem.

  1. using System.Collections;
  2. using Microsoft.Office.Interop.Excel;
  3. using System;
  4. using System.Reflection;
  5. class Sample
  6. {
  7. static void Main()
  8. {
  9. string file = @"c:\csnet\jap\ex1\sample1.xls";
  10. Microsoft.Office.Interop.Excel.ApplicationClass ap = new ApplicationClass();
  11. Missing m=Missing.Value;
  12. Workbook wb=ap.Workbooks.Open(file, m, m, m, m, m, m, m, m, m, m, m, m, m, m);
  13. Worksheet sh =(Worksheet) wb.Sheets[1];
  14. for (int i = 1; i < 10; i++)
  15. {
  16.  
  17. string[] p = new string[10];
  18. for (int j = 1; j <= 10; j++)
  19. {
  20. Range r = (Range)sh.Cells[i, j];
  21. p[j - 1] = r.Value2;
  22. }
  23.  
  24. }
  25. ap.Quit();
  26.  
  27. }
  28. }
Last edited by adatapost; May 20th, 2009 at 10:32 am.
Reply With Quote