0

is it possible to create a binary excel file in asp classic?

the common method is using this

Response.ContentType = "application/octet-stream"

Response.AddHeader "Content-Disposition", "attachment; filename=test.txt"

which is not a "true" excel file

4

1 に答える 1

0

.netでは、Microsoft.Office.Interop.Excel名前空間を使用できます。.netにアクセスできる場合は、非常に使いやすいです。

あなたは「純粋なaspで」と言います-これがcomオブジェクトなどなしを意味するなら-私はそれが可能だとは思いません。

ただし、comオブジェクトを使用するオプションを使用して従来のaspを使い続けたい場合は、Interop comオブジェクトを使用して完全なバイナリスプレッドシートを作成できます。これを行うには、WebサーバーにExcelをインストールする必要があります。

たとえば、ディスク上の空のExcelファイル(つまりテンプレート)を開くには、値を変更して、完成したファイルを保存します。

'#### Ready Excel
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Application.Visible = True

'#### Open a blank Excel File
Set ExcelBook = ExcelApp.workbooks.Open("d:\wwwroot2\blankTemplate.xls")

'#### Select a sheet and change the value of a cell
ExcelBook.Worksheets("SheetName").Cells(1, 1).Value = "Lorem Ipsum"

'#### Switch between sheets
ExcelBook.Worksheets("AnotherSheetName").Select

'#### Save the finished file with a different name (to leave the template ready for easy re-use)
ExcelBook.SaveAs "d:\wwwroot2\FinishedFile.xls"

'#### Tidy up
ExcelBook.Close
ExcelApp.Application.Quit
Set ExcelApp = Nothing 
Set ExcelBook = Nothing

このメソッドの良いところは、interop comオブジェクトがVBAメソッドなどを非常によく模倣していることです。そのため、何かを行う方法がわからない場合は、Excelでマクロを記録し、生のvba、それが生成するコード、具体的にはメソッドとパラメーターを表示します。ほとんどの場合、comオブジェクトに使用するコードと非常によく似ています。

于 2012-06-27T18:24:14.393 に答える