Microsoft.Office.Interop.Excel.dll version 14.0
//File Upload
btn_dr_fp_Click(null, null);
string wjm = "";
if (ViewState["zrpzy085"] != null)
{
wjm = ViewState["zrpzy085"].ToString();
}
System.Threading.Thread.Sleep(1000);
string strFileName=Server.MapPath("~/exceldr/") + wjm;
object missing = System.Reflection.Missing.Value;
Application excel = new Application();//lauch excel application
if (excel == null)
{
Response.Write("<script>alert('Can't access excel')</script>");
}
else
{
excel.Visible = false; excel.UserControl = true;
// Open the file in read-only form of EXCEL
Workbook wb = excel.Application.Workbooks.Open(strFileName, missing, true, missing, missing, missing,
missing, missing, missing, true, missing, missing, missing, missing, missing);
// get the first workbook
Worksheet ws = (Worksheet)wb.Worksheets.get_Item(1);
// Get the total number of rows (including the title bar)
int rowsint = ws.UsedRange.Cells.Rows.Count; // get the number of rows
//have a test
// this.Lbl_ts.Text = rowsint.ToString (); open excel success
// determines whether the cell is merged
// Range excelRange =ws.UsedRange;
try
{
/*
Range oCurCell;
oCurCell = ((Range)excelRange.Cells[6, 0]).MergeCells;
if(oCurCell!=null)
{
this.Lbl_ts.Text = "is merged cells";
}
*/
// Range subRange = (Range)excelRange.Cells[6, 0];
Range rng1 = ws.Cells.get_Range("A8", "A8");
if(rng1.MergeCells)
{
this.Lbl_ts.Text = "is merged cells";
}
else
{
this.Lbl_ts.Text = "not merged cells";
}
}
catch(Exception err)
{
this.Lbl_ts.Text = err.Message;
}
finally
{
excel.Quit(); excel = null;
Process[] procs = Process.GetProcessesByName("excel");
foreach (Process pro in procs)
{
pro.Kill (); // no better way, only to kill the process
}
GC.Collect();
}
}