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

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

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

    我正在使用OfficeWeb组件在Excel模板中填充值。模板采用ExcelXML格式,包含所有相关字段和布局选项,包括页面布局、本例中的横向布局。我用下面的代码用一些实字段填充这个模板。

    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 回复  |  直到 15 年前
        1
  •  0
  •   Pete Duncanson    15 年前

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

    如果您正在进行XSL转换,那么为什么不使用与本文类似的domxmldocument:

    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    15 年前

    在对模板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>