#region
Excel.Application excel = null;
Excel.Workbooks wbs = null;
Excel.Workbook wb = null;
Excel.Worksheet ws = null;
Excel.Range range1 = null;
object Nothing = System.Reflection.Missing.Value;
try
{
excel = new Excel.Application();
excel.UserControl = true;
excel.DisplayAlerts = false;
excel.Application.Workbooks.Open(filename, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing);
// excel.Application.Workbooks.Add(true);//zj
wbs = excel.Workbooks;
wb = wbs[1];
ws = (Excel.Worksheet)wb.Worksheets["Sheet1"];
int rowCount = ws.UsedRange.Rows.Count;
int colCount = ws.UsedRange.Columns.Count;
//object[,] row = new object[rowCount-1, colCount];
for (int i = 0; i < rowCount-1; i++)//
{
DataRow mx;
mx = dsDB.Tables["DBMX"].NewRow();
object[] row = new object[colCount];//object[] row = new object[4];
for (int j = 0; j < colCount; j++)
{
range1 = ws.get_Range(ws.Cells[i + 2, j + 1],
ws.Cells[i + 2, j + 1]);
row[j] = range1.Value;
}
mx["LOT"] = lot;
mx["DBMX_DH"] = "D0101040101013";
mx["DBMX_GLM"] = row[0];//j
mx["DBMX_CC"] = row[1];
mx["DBMX_SL"] = row[2];
mx["DBMX_DW"] = "";
mx["STATE"] = 0;
mx["ERROR_FLAG"] = false;
mx["ERROR_REASON"] = "test";
mx["CREATED_BY"] = userID;
mx["CREATION_DATE"] = mytime;
mx["LAST_UPDATE_BY"] = userID;
mx["LAST_UPDATE_DATE"] = mytime;
dsDB.Tables["DBMX"].Rows.Add(mx);
}
//dsDB.Tables["DBMX"].Rows.Add(mx);
POS.Update_DBMX_INTERFACE(BASEINFO.SerializationDataset(dsDB), lot.ToString(), 1); //??;@
}
finally
{
if (excel != null)
{
if (wbs != null)
{
if (wb != null)
{
if (ws != null)
{
if (range1 != null)
{
System.Runtime.InteropServices.Marshal.
ReleaseComObject(range1);
range1 = null;
}
System.Runtime.InteropServices.Marshal.
ReleaseComObject(ws);
ws = null;
}
wb.Close(false, Nothing, Nothing);
System.Runtime.InteropServices.Marshal.
ReleaseComObject(wb);
wb = null;
}
wbs.Close();
System.Runtime.InteropServices.Marshal.
ReleaseComObject(wbs);
wbs = null;
}
excel.Application.Workbooks.Close();
excel.Quit();
System.Runtime.InteropServices.Marshal.
ReleaseComObject(excel);
excel = null;
GC.Collect();
}
}
//catch (Exception E)
//{
// if (sError != "")
// MessageBox.Show(sError);
// else
// MessageBox.Show(E.Message.ToString());
//}
#endregion