Einzelnen Beitrag anzeigen

khh

Registriert seit: 18. Apr 2008
Ort: Südbaden
1.929 Beiträge
 
FreePascal / Lazarus
 
#1

XML-File die zweite, Kindeskinder?

  Alt 25. Jun 2015, 08:59
Hallo zusammen,
mit
Delphi-Quellcode:
 doc := TXMLDocument.Create;
      try
         doc.XMLVersion := '1.0';
         doc.AppendChild(doc.CreateProcessingInstruction('mso-application', 'progid="Excel.Sheet"'));

         nRoot := doc.CreateElement('Workbook');
         TDOMElement(nRoot).SetAttribute('xmlns', 'urn:schemas-microsoft-com:office:spreadsheet');
         TDOMElement(nRoot).SetAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
         TDOMElement(nRoot).SetAttribute('xmlns:x', 'urn:schemas-microsoft-com:office:excel');
         TDOMElement(nRoot).SetAttribute('xmlns:ss', 'urn:schemas-microsoft-com:office:spreadsheet');
         TDOMElement(nRoot).SetAttribute('xmlns:html', 'http://www.w3.org/TR/REC-html40');
         doc.AppendChild(nRoot);

         nDocProperties := doc.CreateElement('DocumentProperties');
         TDOMElement(nDocProperties).SetAttribute('xmlns', 'urn:schemas-microsoft-com:office:office');
         nRoot.AppendChild(nDocProperties);

         AddTextNode(nDocProperties, 'Author', 'ich');
         AddTextNode(nDocProperties, 'LastAuthor', 'ich');
         AddTextNode(nDocProperties, 'Created', FormatDateTime('yyyy-mm-dd', Now) + 'T' + FormatDateTime('hh:nn:ss', Now) + 'Z');
         AddTextNode(nDocProperties, 'Version', '15.0');

         nDocSettings := doc.CreateElement('OfficeDocumentSettings');
         TDOMElement(nDocSettings).SetAttribute('xmlns', 'urn:schemas-microsoft-com:office:office');
         nRoot.AppendChild(nDocSettings);

         nDocSettings.AppendChild(doc.CreateElement('AllowPNG'));
         //////////////////////////
         nDocSettings := doc.CreateElement('ExcelWorkbook');
         TDOMElement(nDocSettings).SetAttribute('xmlns', 'urn:schemas-microsoft-com:office:excel');
         nRoot.AppendChild(nDocSettings);
         AddTextNode(nDocSettings, 'WindowHeight', '12435');
         AddTextNode(nDocSettings, 'WindowWidth', '2880');
         AddTextNode(nDocSettings, 'WindowTopX', '0');
         AddTextNode(nDocSettings, 'WindowTopY', '0');
         AddTextNode(nDocSettings, 'ProtectStructure', 'False');
         AddTextNode(nDocSettings, 'ProtectWindows', 'False');
         ////////////////////////////
         nDocSettings := doc.CreateElement('Styles');

         nChild:= nDocSettings.AppendChild(doc.CreateElement('Style'));
         TDOMElement(nChild).SetAttribute('ss:ID', 'Default');
         TDOMElement(nChild).SetAttribute('ss:Name', 'Normal');

         nRoot.AppendChild(nDocSettings);
...
...
erstelle ich folgendes Fragment:

Delphi-Quellcode:
<?xml version="1.0" encoding="utf-8"?>
<?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>ich</Author>
    <LastAuthor>ich</LastAuthor>
    <Created>2015-06-25T08:50:13Z</Created>
    <Version>15.0</Version>
  </DocumentProperties>
  <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
    <AllowPNG/>
  </OfficeDocumentSettings>
  <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
    <WindowHeight>12435</WindowHeight>
    <WindowWidth>2880</WindowWidth>
    <WindowTopX>0</WindowTopX>
    <WindowTopY>0</WindowTopY>
    <ProtectStructure>False</ProtectStructure>
    <ProtectWindows>False</ProtectWindows>
  </ExcelWorkbook>
  <Styles>
    <Style ss:ID="Default" ss:Name="Normal"/>
  </Styles>
</Workbook>
dafür vielen Dank an CCRDude

inner halb des Style-Nodes benötige ich weiter Kind-Notes, wie krieg ich das hin?
Ich verzweifle gerade, wenn ich mir dazu das ganze XML DOM-Tutorial durcharbeiten muss

so soll das Style-Fragment werden:

Delphi-Quellcode:
<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>
    <Style ss:ID="s62">
      <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="20" ss:Color="#000000" ss:Bold="1" />
    </Style>
</Styles>
ich danke euch gewaltig für eure Hilfen
Karl-Heinz
  Mit Zitat antworten Zitat