2013-06-12 33 views
0

我有一個即時的需求,我需要從駐留在系統上的現有Excel文件打開一些特定的Excel工作表。我想知道如何使用經典ASP來實現。我試圖在互聯網上搜索,但找不到任何具體的東西。需要一些建議... :)如何使用傳統的asp打開現有的Excel文件

我希望這是有道理的

我想下面的代碼,但一切都是徒勞。

<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

你有沒有發現一些代碼?你寫的東西了嗎?你爲什麼要打開一個文件?你的動機是哪一個。 – mike27015

+0

我嘗試了下面的代碼,但都是徒勞的。 'HTML> <體BGCOLOR = 「白色」 文本= 「黑」> <%昏暗xlObject,xlBook,WKS 集xlObject =的CreateObject( 「Excel.Application」) xlObject.visible =假 集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 集周=無 集xlBook =無 集xlObject =無%> ' –

回答

-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

+0

感謝您的所有幫助,但我知道如何在c#中完成此任務。您能否使用傳統的ASP提供一些編碼方面的建議?需要根據公司要求完成此項工作。 –

+0

您可以在這裏找到更深層次的解決方案:http://www.shotdev.com/asp/asp-excel/asp-open-excel-on-specified-worksheet/ – mike27015

+1

我會研究它並在此處提供反饋。非常感謝你 –