简体   繁体   English

使用经典asp创建多张excel文件

[英]creating multi sheet excel file using classic asp

I am working on a project and I need to create a multi sheet excel file using classic asp.我正在做一个项目,我需要使用经典的 asp 创建一个多页 excel 文件。

Here is my code.这是我的代码。 It makes a multi sheet excel but I cant write anything on sheet 2 or 3:它制作了一张多张纸 excel 但我不能在第 2 或第 3 页上写任何东西:

<%
  response.charset = "UTF-8"
  Response.Buffer=true

  Response.AddHeader "Content-Disposition", "attachment;filename=aaa.xls"  
  Response.ContentType = "application/vnd.ms-excel" 
%>
<HTML xmlns:x="urn:schemas-microsoft-com:office:excel">
<HEAD>
<xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>sheet1</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
<x:ExcelWorksheet>
<x:Name>sheet2</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml>
</HEAD>
<BODY>
<TABLE>
<%
dim  oConn
Set oConn = Server.CreateObject("ADODB.Connection")
Dim rs, ds
Set rs = Server.CreateObject("ADODB.Recordset")
Response.Write "<tr>"
Response.Write "<td style='border-left:none;border:.5pt solid windowtext;' bgcolor='#CCCCCC' bordercolor='#000000'><b>"
Response.Write "aa"
Response.Write "</b></td>"
Response.Write "</tr>"
Response.Write "<tr>"
Response.Write "<td>"
Response.Write "bb"
Response.Write "</td>"
Response.Write "</tr>"
%>
</TABLE>
</BODY>
</HTML>

I don't think it's possible to create actual.xls /.xlsx files in Classic ASP without a third party component (such as EasyXLS.ExcelDocument).我认为在没有第三方组件(例如 EasyXLS.ExcelDocument)的情况下,不可能在 Classic ASP 中创建实际的.xls /.xlsx 文件。

But what you can do is generate your Excel file using XML markup within Classic ASP, export it with a.xls extension and Excel will convert the file when you open it (after a warning message).但是您可以做的是使用经典 ASP 中的 XML 标记生成您的 Excel 文件,使用 a.xls 扩展名和 Excel 导出文件(在您打开文件时会转换文件)。

For example:例如:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%

    Response.Charset = "UTF-8"
    Response.AddHeader "Content-Disposition", "attachment;filename=aaa.xls"  
    Response.ContentType = "application/vnd.ms-excel" 

%><?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">
 <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
  <Author>Author Name</Author>
  <LastAuthor>Author Name</LastAuthor>
  <Created>2020-05-20T13:19:37Z</Created>
  <LastSaved>2020-05-20T13:21:04Z</LastSaved>
  <Company>Company Name</Company>
  <Version>14.00</Version>
 </DocumentProperties>
 <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
  <AllowPNG/>
 </OfficeDocumentSettings>
 <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  <WindowHeight>4695</WindowHeight>
  <WindowWidth>14355</WindowWidth>
  <WindowTopX>360</WindowTopX>
  <WindowTopY>105</WindowTopY>
  <ActiveSheet>2</ActiveSheet>
  <ProtectStructure>False</ProtectStructure>
  <ProtectWindows>False</ProtectWindows>
 </ExcelWorkbook>
 <Styles>
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
 </Styles>
 <Worksheet ss:Name="Sheet1">
  <Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1"
   x:FullRows="1" ss:DefaultRowHeight="15">
   <Row>
    <Cell><Data ss:Type="String">1A - Sheet 1</Data></Cell>
   </Row>
  </Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <PageSetup>
    <Header x:Margin="0.3"/>
    <Footer x:Margin="0.3"/>
    <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
   </PageSetup>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
 </Worksheet>
 <Worksheet ss:Name="Sheet2">
  <Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1"
   x:FullRows="1" ss:DefaultRowHeight="15">
   <Row>
    <Cell><Data ss:Type="String">1A - Sheet 2</Data></Cell>
   </Row>
  </Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <PageSetup>
    <Header x:Margin="0.3"/>
    <Footer x:Margin="0.3"/>
    <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
   </PageSetup>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
 </Worksheet>
 <Worksheet ss:Name="Sheet3">
  <Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1"
   x:FullRows="1" ss:DefaultRowHeight="15">
   <Row>
    <Cell><Data ss:Type="String">1A - Sheet 3</Data></Cell>
   </Row>
  </Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <PageSetup>
    <Header x:Margin="0.3"/>
    <Footer x:Margin="0.3"/>
    <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
   </PageSetup>
   <Selected/>
   <Panes>
    <Pane>
     <Number>3</Number>
     <ActiveRow>6</ActiveRow>
     <ActiveCol>3</ActiveCol>
    </Pane>
   </Panes>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
 </Worksheet>
</Workbook>

The above example has 3 populated sheets.上面的示例有 3 个填充的工作表。 Best thing to do would be to create a dummy template of the type of Excel layout you're looking to generate, populate the sheets with dummy data and export from Excel using the "XML Spreadsheet" format (which is all I did for the above example).最好的办法是创建一个您要生成的 Excel 布局类型的虚拟模板,用虚拟数据填充表格并使用“XML 电子表格”格式从 Excel 导出(这就是我为上述所做的一切例子)。 Then use Classic ASP to replace the dummy data with actual data.然后使用 Classic ASP 将虚拟数据替换为实际数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM