Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6890093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:14:17+00:00 2026-05-27T06:14:17+00:00

I have an Excel (xls) template with example data. I need to prepare an

  • 0

I have an Excel (xls) template with example data. I need to prepare an Excel file with dynamically- generated data.

First, I made an XML file from the corresponding xls.
The XML file looks like this :

<?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>Op</Author>
  <LastAuthor>ufoq</LastAuthor>
  <Created>2011-11-18T06:54:25Z</Created>
  <LastSaved>2011-12-05T11:43:26Z</LastSaved>
  <Version>11.9999</Version>
 </DocumentProperties>
 <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  <WindowHeight>9750</WindowHeight>
  <WindowWidth>23310</WindowWidth>
  <WindowTopX>480</WindowTopX>
  <WindowTopY>405</WindowTopY>
  <ProtectStructure>False</ProtectStructure>
  <ProtectWindows>False</ProtectWindows>
 </ExcelWorkbook>
 <Styles>
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font x:CharSet="238" x:Family="Swiss" ss:Size="8" ss:Color="#000000"/>
   <Interior/>
   <NumberFormat/>
......

Now I placed this content in symfony view and filled it with my generated data.
I need to output in XML file format but I don’t know how to to this.
The new file must have the same structure as the template file so I cannot make a new file from scratch.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:14:18+00:00Added an answer on May 27, 2026 at 6:14 am

    Looks like you have documents in the openxml format which you can process with the PHPExcel library.


    If you just want to replace some simple values in your template you could also use DOMDocument and DOMXPath to process the xml document, e.g.

    <?php
    $doc = new DOMDocument;
    $doc->loadxml( getData() );
    $xpath = new DOMXPath($doc);
    $xpath->registerNamespace('o', "urn:schemas-microsoft-com:office:office");
    $xpath->registerNamespace('x', "urn:schemas-microsoft-com:office:excel");
    $xpath->registerNamespace('ss', "urn:schemas-microsoft-com:office:spreadsheet");
    $xpath->registerNamespace('html', "http://www.w3.org/TR/REC-html40");
    
    foreach( $xpath->query('/ss:Workbook/o:DocumentProperties/o:LastAuthor') as $n ) {
        //echo '.';
        $text = $doc->createTextnode('SO Test');
        $n->replaceChild($text, $n->firstChild);
    }
    echo $doc->savexml();
    
    function getData() {
        return <<< eox
    <?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>Op</Author>
      <LastAuthor>ufoq</LastAuthor>
      <Created>2011-11-18T06:54:25Z</Created>
      <LastSaved>2011-12-05T11:43:26Z</LastSaved>
      <Version>11.9999</Version>
     </DocumentProperties>
     <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
      <WindowHeight>9750</WindowHeight>
      <WindowWidth>23310</WindowWidth>
      <WindowTopX>480</WindowTopX>
      <WindowTopY>405</WindowTopY>
      <ProtectStructure>False</ProtectStructure>
      <ProtectWindows>False</ProtectWindows>
     </ExcelWorkbook>
     <Styles>
      <Style ss:ID="Default" ss:Name="Normal">
       <Alignment ss:Vertical="Bottom"/>
       <Borders/>
       <Font x:CharSet="238" x:Family="Swiss" ss:Size="8" ss:Color="#000000"/>
       <Interior/>
       <NumberFormat/>
       [...]
      </Style> 
     </Styles>
    </Workbook>
    eox;
    }
    

    update: If you want the client to recognize the file type you have to set the content (mime) type to the approriate value, see Office 2007 File Format MIME Types for HTTP Content Streaming. E.g.

    $spreadsheet = new DOMDocument;
    $spreadsheet->loadxml(getData());
    someProcessing($spreadsheet);
    if ( headers_sent() ) {
        die('error: headers already sent');
    }
    header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    echo $spreadsheet->save('php://output');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to pull data from an excel file (.xls or .xlsx) and display
I need to restrict users from opening an Excel (.xls) file with notepad. I
I have a Perl script that reads data from an Excel ( xls )
We have an automatic process that opens a template excel file, writes rows of
I'm building an iPhone app that has to download an Excel (.xls) file from
Lets say I have an Excel file named DataSheet.xls open. How can I kill
I have an excel file that i need to open and search it. This
Is it possible to extract information from an excel file (.xls) into c# on
I have an excel template that uses a macro to save the file, so
I have an Excel file Country.xls. This Excel file contains two sheet/records Country and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.