Read File Excel Using C#
//Utility Excel
using Excel = Microsoft.Office.Interop.Excel;
using System.Globalization;
private void OpenMyExcelFile()
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
string str;
int rCnt = 0;
int cCnt = 0;
string Looping="";
string mypath="book1.xls";
object misValue = System.Reflection.Missing.Value;
System.Globalization.CultureInfo CI = new System.Globalization.CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentCulture = CI;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open(myPath.trim(), 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
string MyColoumB11 = xlWorkSheet.get_Range("B11", "B11").Value2.ToString();
string MyColoumB12= xlWorkSheet.get_Range("B12", "B12").Value2.ToString();
for (int i = 11; i < 31; i++)
{
Looping= Looping + i.ToString();
try
{
//Looping Data pada Kolom B, start B11 --> B30
string myData = xlWorkSheet.get_Range(Looping.Trim(), Looping.Trim()).Value2.ToString();
Looping= "B";
}
catch
{
}
}
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
Post a Comment