Advertisement
krot

XML Excel Writer

Nov 8th, 2016
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.79 KB | None | 0 0
  1. <?
  2. class XML{
  3. public $HND;
  4. public $row;
  5. function Worksheet_Init($title){
  6. $this->row=0;
  7. //ss:ExpandedRowCount="9"
  8. fwrite($this->HND,'<Worksheet ss:Name="'.$title.'">
  9. <Table ss:ExpandedColumnCount="12" x:FullColumns="1"
  10. x:FullRows="1" ss:StyleID="s21" ss:DefaultRowHeight="14.55">
  11. <Column ss:StyleID="s21" ss:AutoFitWidth="0" ss:Width="43"/>
  12.   <Column ss:StyleID="s21" ss:AutoFitWidth="0" ss:Width="81"/>
  13.   <Column ss:StyleID="s21" ss:AutoFitWidth="0" ss:Width="270"/>
  14.   <Column ss:StyleID="s21" ss:AutoFitWidth="0" ss:Width="49"/>
  15.   <Column ss:StyleID="s21" ss:AutoFitWidth="0" ss:Width="50"/>
  16.   <Column ss:StyleID="s21" ss:AutoFitWidth="0" ss:Width="48" ss:Span="6"/>
  17.   <Row ss:AutoFitHeight="0" ss:Height="25.8">
  18.    <Cell ss:MergeAcross="11" ss:StyleID="s23"><Data ss:Type="String">LOGO</Data></Cell>
  19.   </Row>
  20.   <Row ss:AutoFitHeight="0">
  21.    <Cell ss:MergeAcross="11" ss:StyleID="s25"><Data ss:Type="String">тел: </Data></Cell>
  22.   </Row>
  23.   <Row ss:AutoFitHeight="0">
  24.    <Cell ss:MergeAcross="11" ss:StyleID="s25"><Data ss:Type="String">Наш адрес: </Data></Cell>
  25.   </Row>
  26.   <Row ss:AutoFitHeight="0">
  27.    <Cell ss:MergeAcross="11"/>
  28.   </Row>
  29.   <Row ss:AutoFitHeight="0">
  30.    <Cell ss:StyleID="s27"><Data ss:Type="String">Склад</Data></Cell>
  31.    <Cell ss:StyleID="s27"><Data ss:Type="String">Артикул</Data></Cell>
  32.    <Cell ss:StyleID="s27"><Data ss:Type="String">Наименование</Data></Cell>
  33.    <Cell ss:StyleID="s27"><Data ss:Type="String">Бренд</Data></Cell>
  34.    <Cell ss:StyleID="s27"><Data ss:Type="String">Количество</Data></Cell>
  35.    <Cell ss:StyleID="s27"><Data ss:Type="String">Цена</Data></Cell>
  36.   </Row>');
  37. }
  38. function Worksheet_End($option=''){
  39. fwrite($this->HND,'</Table>
  40.  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
  41.   <FreezePanes/>
  42.   <FrozenNoSplit/>
  43.   <SplitHorizontal>5</SplitHorizontal>
  44.   <TopRowBottomPane>5</TopRowBottomPane>
  45.   <ActivePane>2</ActivePane>
  46.   <Panes>
  47.    <Pane>
  48.     <Number>3</Number>
  49.    </Pane>
  50.    <Pane>
  51.     <Number>2</Number>
  52.     <ActiveCol>0</ActiveCol>
  53.    </Pane>
  54.   </Panes>
  55.  </WorksheetOptions>
  56.  <AutoFilter x:Range="R5C1:R65505C6"
  57.   xmlns="urn:schemas-microsoft-com:office:excel">
  58.  </AutoFilter>
  59. </Worksheet>');
  60.  
  61.  /*
  62.  
  63.  fwrite($this->HND,'</Table>
  64.   <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
  65.    <PageSetup>
  66.     <PageMargins x:Bottom="0.984251969" x:Left="0.78740157499999996"
  67.      x:Right="0.78740157499999996" x:Top="0.984251969"/>
  68.    </PageSetup>
  69.    <Unsynced/>
  70.    '.$option.'
  71.    <FreezePanes/>
  72.    <FrozenNoSplit/>
  73.    <SplitHorizontal>5</SplitHorizontal>
  74.    <TopRowBottomPane>5</TopRowBottomPane>
  75.    <ActivePane>2</ActivePane>
  76.    <Panes>
  77.     <Pane>
  78.      <Number>3</Number>
  79.     </Pane>
  80.     <Pane>
  81.      <Number>2</Number>
  82.     </Pane>
  83.    </Panes>
  84.    <ProtectObjects>False</ProtectObjects>
  85.    <ProtectScenarios>False</ProtectScenarios>
  86.   </WorksheetOptions>
  87.   <AutoFilter x:Range="R5C1:R65505C6"
  88.    xmlns="urn:schemas-microsoft-com:office:excel">
  89.   </AutoFilter>
  90.  </Worksheet>');*/
  91.  
  92. }
  93. function Worksheet_ROW($stock,$art,$name,$brand,$count,$price){
  94. if($this->row<65531){fwrite($this->HND,'<Row ss:AutoFitHeight="0">
  95. <Cell ss:StyleID="s28"><Data ss:Type="String">'.$stock.'</Data></Cell>
  96. <Cell ss:StyleID="s28"><Data ss:Type="String">'.$art.'</Data></Cell>
  97. <Cell ss:StyleID="s28"><Data ss:Type="String">'.$name.'</Data></Cell>
  98. <Cell ss:StyleID="s28"><Data ss:Type="String">'.$brand.'</Data></Cell>
  99. <Cell ss:StyleID="s28"><Data ss:Type="'.(is_int($count)?'Number':'String').'">'.$count.'</Data></Cell>
  100. <Cell ss:StyleID="s29"><Data ss:Type="Number">'.$price.'</Data></Cell>
  101. </Row>');
  102. return $this->row++;
  103. }return -1;
  104. }
  105. function XML($filename,$option=''){
  106. /*header("Content-Type:application/vnd.ms-excel");
  107. header("Content-Disposition:attachment;filename=price.xls");*/
  108.  
  109. $this->HND=fopen($filename,'w');
  110. if($this->HND===false)exit('FILE');
  111.  
  112. fwrite($this->HND,'<?xml version="1.0"?>
  113. <?mso-application progid="Excel.Sheet"?>
  114. <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
  115. xmlns:o="urn:schemas-microsoft-com:office:office"
  116. xmlns:x="urn:schemas-microsoft-com:office:excel"
  117. xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
  118. xmlns:html="http://www.w3.org/TR/REC-html40">');
  119. fwrite($this->HND,'<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
  120.  <Title>Price</Title>
  121.  <Author>Price</Author>
  122.  <LastAuthor>price</LastAuthor>
  123.  <LastPrinted>'.date('Y-m-d').'T'.date('H:i:s').'Z</LastPrinted>
  124.  <Created>'.date('Y-m-d').'T'.date('H:i:s').'Z</Created>
  125.  <LastSaved>'.date('Y-m-d').'T'.date('H:i:s').'Z</LastSaved>
  126.  <Version>11.9999</Version>
  127. </DocumentProperties>
  128. <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
  129.  <Colors>
  130.   <Color>
  131.    <Index>2</Index>
  132.    <RGB>#E7EBDA</RGB>
  133.   </Color>
  134.   <Color>
  135.    <Index>3</Index>
  136.    <RGB>#686868</RGB>
  137.   </Color>
  138.  </Colors>
  139. </OfficeDocumentSettings>
  140. <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  141.  <WindowHeight>5496</WindowHeight>
  142.  <WindowWidth>9660</WindowWidth>
  143.  <WindowTopX>0</WindowTopX>
  144.  <WindowTopY>0</WindowTopY>
  145.  <ProtectStructure>False</ProtectStructure>
  146.  <ProtectWindows>False</ProtectWindows>'.$option.'
  147. </ExcelWorkbook>
  148. <Styles>
  149.  <Style ss:ID="Default" ss:Name="Normal">
  150.   <Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
  151.   <Borders/>
  152.   <Font ss:FontName="Calibri" ss:Size="11" ss:Color="#000000"/>
  153.   <NumberFormat/>
  154.  </Style>
  155.  <Style ss:ID="s21">
  156.   <Interior/>
  157.   <Protection/>
  158.  </Style>
  159.  <Style ss:ID="s23">
  160.   <Font ss:FontName="Calibri" x:CharSet="204" x:Family="Swiss" ss:Size="24"
  161.    ss:Color="#FF6600"/>
  162.   <Interior/>
  163.   <Protection/>
  164.  </Style>
  165.  <Style ss:ID="s25">
  166.   <Font ss:FontName="Calibri" ss:Size="11" ss:Color="#000000" ss:Bold="1"/>
  167.   <Interior/>
  168.   <Protection/>
  169.  </Style>
  170.  <Style ss:ID="s27">
  171.   <Borders>
  172.    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"
  173.     ss:Color="#686868"/>
  174.    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"
  175.     ss:Color="#686868"/>
  176.    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"
  177.     ss:Color="#686868"/>
  178.    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"
  179.     ss:Color="#686868"/>
  180.   </Borders>
  181.   <Font ss:FontName="Times New Roman" ss:Size="9" ss:Color="#000000" ss:Bold="1"/>
  182.   <Interior ss:Color="#E7EBDA" ss:Pattern="Solid"/>
  183.   <Protection/>
  184.  </Style>
  185.  <Style ss:ID="s28">
  186.   <Borders>
  187.    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"
  188.     ss:Color="#686868"/>
  189.    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"
  190.     ss:Color="#686868"/>
  191.    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"
  192.     ss:Color="#686868"/>
  193.    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"
  194.     ss:Color="#686868"/>
  195.   </Borders>
  196.   <Interior/>
  197.   <Protection/>
  198.  </Style>
  199.  <Style ss:ID="s29">
  200.   <Borders>
  201.    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"
  202.     ss:Color="#686868"/>
  203.    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"
  204.     ss:Color="#686868"/>
  205.    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"
  206.     ss:Color="#686868"/>
  207.    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"
  208.     ss:Color="#686868"/>
  209.   </Borders>
  210.   <Interior/>
  211. <Protection/>
  212.  </Style>
  213. </Styles>');
  214. }
  215. function __destruct(){
  216. fwrite($this->HND,'</Workbook>');
  217. fclose($this->HND);
  218. }
  219.  
  220.  
  221.  
  222. }
  223.  
  224. $XMLList=new XML($GLOBALS['patchTMP']."/A-z.xls");//доп лист
  225. $XMLList->Worksheet_Init('A-z');
  226.  
  227. $XMLList->Worksheet_ROW($row['STOCK'],$row['ART'],$row['NAME'],$row['BRAND'],$row['COUNTS'],$row['PRICE']);
  228.  
  229.  
  230. $XMLList->Worksheet_End();
  231. unset($XMLList);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement