代码之家  ›  专栏  ›  技术社区  ›  edosoft

使用Office Web组件更改页面布局

  •  0
  • edosoft  · 技术社区  · 16 年前

    Set objSpreadsheet = Server.CreateObject("OWC11.Spreadsheet")
    objSpreadsheet.XMLURL = Server.MapPath("xml") & "\MR1_Template.xls"
    
    'Fill cells with values here
    Response.ContentType = "application/vnd.ms-excel"
    Response.AddHeader "Content-Disposition", "inline; filename=" & strFileNaam
    Response.write objSpreadsheet.xmlData
    

    保存新Excel文件后,页面布局选项将消失。我查看了OWC的API文档,但找不到指定横向页面的选项

    2 回复  |  直到 16 年前
        1
  •  0
  •   Pete Duncanson    16 年前

    我不确定你是否传递了正确的数据。XMLURL似乎是一个奇怪的方法名称,需要将XSL模板传递给?

    http://www.codeproject.com/KB/XML/xml_spreadsheet_to_csv.aspx

    轻松剪切和粘贴:

    Dim xslt As New XslTransform
    'Load the stylesheet.
    
    xslt.Load(Server.MapPath(".") & "excel2csv.xsl")
    
    Dim doc As New XmlDocument
    'xmldata is string, use doc.Load(fileName) for file.
    
    doc.LoadXml(xmlData)
    
    'Create an XmlTextWriter which outputs to a file.
    
    Dim fileName As String
    fileName = Server.MapPath(".") & "book.csv"
    
    Dim writer As XmlWriter = New XmlTextWriter(fileName, Nothing)
    'Transform the data and send the output to the console.
    
    
    xslt.Transform(doc, Nothing, writer, Nothing)
    writer.Close()
    
        2
  •  0
  •   edosoft    16 年前

    在对模板excel表(作为xml)和生成的xmlData进行了一些详细比较后,我决定修改生成的xml中的页面布局。以下是我添加的选项:

    <x:WorksheetOptions>
      <x:PageSetup><x:Layout x:Orientation="Landscape"/></x:PageSetup>
      <x:FitToPage/>
      <x:Print>
        <x:FitWidth>2</x:FitWidth>
        <x:ValidPrinterInfo/>
        <x:PaperSizeIndex>9</x:PaperSizeIndex>
        <x:Scale>87</x:Scale>
      </x:Print>
    </x:WorksheetOptions>
    
    推荐文章