日期:2014-05-17 浏览次数:20923 次
Excel.Workbooks xlWorkbooks;
Excel.Workbook xlWorkbook;
Excel.Worksheet xlWorksheet;
System.Type tyWorkbooks;
System.Reflection.MethodInfo[] methods;
object objFilePath;
object oMissing = System.Reflection.Missing.Value;
try
{
xlApp.Visible = false;
xlWorkbooks = xlApp.Workbooks;
tyWorkbooks = xlWorkbooks.GetType();
methods = tyWorkbooks.GetMethods();
objFilePath = fileName;
xlWorkbook = (Excel.Workbook)tyWorkbooks.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod,
null,
xlWorkbooks,
new object[] { objFilePath, true, true });
int vaildcount = 0;
foreach (Excel.Worksheet item in xlWorkbook.Worksheets)
{
if (item != null && item.Rows.Count > 0 && item.Columns.Count > 0)
{
if (item.UsedRange.Value == null || item.UsedRange.Value.ToString() == "")
{
//....
}