This is my code :
Microsoft.Office.Interop.Excel.Application();
string filePath = Server.MapPath(@"~\\Staf\\TestLucene\\" + strFileName.ToString());
Microsoft.Office.Interop.Excel.Workbook workbook = application.Workbooks.Open(filePath, 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);
int numSheet = workbook.Sheets.Count;
for (int num = 1; num < numSheet + 1; num++)
{
Microsoft.Office.Interop.Excel.Worksheet sheet = (Worksheet)workbook.Worksheets[num];
Range excelRange = (Range) sheet.get_Range("A1", "H10");
object[,] valueArray = (object[,])excelRange.Value2;
for (int i = 1; i <= valueArray.GetLength(0); i++ )
{
for (int j = 1; j <= valueArray.GetLength(1); j++)
{
string text = Convert.ToString(valueArray[i, j]);
}
}
}
// Close word.
workbook.Close(false);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
application.Application.Quit();
|
With this code, I just got the information in range A1:H10. Can I make it automatic? Like when I count of existing sheets in workbook?
int numSheet = workbook.Sheets.Count;
it means I will always read no matter how much the existing sheet in a workbook.
cz I 'll do looping as much as number of that sheet.
Can I do this thing in range?
so that I should not determining the range A1:H10
Im sorry if its Code is messy, or if i missed to give any info. i just dont know what i should post to help you giving me an answer.
thx,
Suthish NairPosted Feb 4, 2011, 2:23 PM
Sam HobbsPosted Feb 2, 2011, 9:35 PM
Note that I did not see your code until I was making a reply. Oooops, now I see it. You can make your code easier to read in forum messages if you put "
" at the end of each line of source code, but if you do that, you must use the HTML tab of the editor.
Suthish NairPosted Feb 2, 2011, 10:26 AM
In excel A1 means Column A and Row Number 1. Same as H10, Coulmn H and Row Number 10.
So you can read/loop the rows in excel sheet upto (new version row count 1048576).
You can also create column list like A,B,C ..... AA, AB,...
using System.Collections.Generic;
Hope this you looking for or something else?