如何使用经典的asp打开现有的Excel文件

时间:2013-06-12 12:11:09

标签: html excel asp-classic

我有一个直接的要求,我需要从驻留在系统上的现有Excel文件中打开一些特定的Excel工作表。我想知道如何使用经典ASP 来实现这一目标。我尝试在互联网上搜索但找不到具体的东西。需要一些建议...... :)

我希望这是有道理的

我尝试了下面的代码,但都是徒劳的。

<html> 
<body bgcolor="white" text="black"> 

        <%Dim xlObject, xlBook,wks Set xlObject = CreateObject("Excel.Application") xlObject.visible = False 
        Set xlBook = xlObject.Workbooks.open("C:\\Users\\Administrator\\Desktop\\Final Help file 11june13.xls") 
        Set wks = xlObject.ActiveWorkBook.Worksheets(1) 
        response.Write("permbajtja e qelizes eshte: "&wks.Cells(3,1)) 
        xlBook.Close xlObject.Quit 
        Set wks = Nothing 
        Set xlBook = Nothing 
        Set xlObject = Nothing %> 
    </form>
</body> 
</html>

1 个答案:

答案 0 :(得分:-2)

例如,如何将您的Excel文件显示到Web浏览器中,这是C#中的一个简单示例。您打算在纯ASP或ASP.NET中编写吗?

public static void ConvertExcelFile(String excelFile)
{
        Microsoft.Office.Interop.Excel.Application excel = null;
        Microsoft.Office.Interop.Excel.Workbook xls = null;
        try
        {
            excel = new Microsoft.Office.Interop.Excel.Application();
            object missing = Type.Missing;
            object trueObject = true;
            excel.Visible = false;
            excel.DisplayAlerts = false;
            xls = excel.Workbooks.Open(excelFile, missing, trueObject, missing,

                    missing, missing, missing, missing, missing, missing, missing, missing,

                    missing, missing, missing);
            object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;
            IEnumerator wsEnumerator=excel.ActiveWorkbook.Worksheets.GetEnumerator();
            int i = 1;
            while (wsEnumerator.MoveNext())
            {
                Microsoft.Office.Interop.Excel.Worksheet wsCurrent =
                (Microsoft.Office.Interop.Excel.Worksheet)wsEnumerator.Current;
                String outputFile =excelFile + "." + i.ToString() + ".html";
                wsCurrent.SaveAs(outputFile, format, missing, missing, missing,
                missing, missing, missing, missing, missing);
                ++i;
            }
            excel.Quit();
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error accessing Excel document.\n\n" +
            ex.Message);
        }
    }

可在以下网址找到:http://bytes.com/topic/c-sharp/answers/477965-excel-files-html-using-c