private
void
OpenExcel(
string
strFileName)
{
object
missing = System.Reflection.Missing.Value;
Application excel =
new
Application();
if
(excel ==
null
)
{
Response.Write(
"<script>alert('Can't access excel')</script>"
);
}
else
{
excel.Visible =
false
; excel.UserControl =
true
;
Workbook wb = excel.Application.Workbooks.Open(strFileName, missing,
true
, missing, missing, missing,
missing, missing, missing,
true
, missing, missing, missing, missing, missing);
Worksheet ws = (Worksheet)wb.Worksheets.get_Item(1);
int
rowsint = ws.UsedRange.Cells.Rows.Count;
Range rng1 = ws.Cells.get_Range(
"B2"
,
"B"
+ rowsint);
Range rng2 = ws.Cells.get_Range(
"K2"
,
"K"
+ rowsint);
object
[,] arryItem= (
object
[,])rng1.Value2;
object
[,] arryCus = (
object
[,])rng2.Value2;
string
[,] arry =
new
string
[rowsint-1, 2];
for
(
int
i = 1; i <= rowsint-1; i++)
{
arry[i - 1, 0] =arryItem[i, 1].ToString();
arry[i - 1, 1] = arryCus[i, 1].ToString();
}
Response.Write(arry[0, 0] +
" / "
+ arry[0, 1] +
"#"
+ arry[rowsint - 2, 0] +
" / "
+ arry[rowsint - 2, 1]);
}
excel.Quit(); excel =
null
;
Process[] procs = Process.GetProcessesByName(
"excel"
);
foreach
(Process pro
in
procs)
{
pro.Kill();
}
GC.Collect();
}
请发表评论