2017-05-23 5 views
0

Ich verwende den Code PHP_XLSXWriter, um eine XLSX-Datei zu generieren. Die Datei wird in Ordnung erzeugt, und sie wird in Excel geöffnet, aber ich verwende diese Datei, um sie auf den DHL-Server hochzuladen, um Versandaufträge zu generieren. Problem ist, dass sich ihr Dienst über eine ungültige Zeile beschwert. Die Daten in dieser Zeile sind eigentlich vollkommen in Ordnung, und Excel kann es lesen, wie ich es erwähnt habe. Als Test habe ich jedoch die von PHP generierte Tabelle als separate Datei gespeichert, wodurch Microsoft Excel als eigenes Format gespeichert wurde. Als ich das Microsoft-Blatt auf den DHL-Server hochgeladen habe, akzeptiert es es ohne Probleme.PHP XLSXWriter - Verschiedene Formatierung

Nachdem Sie einen Hexvergleich der beiden gemacht hatten, waren sie völlig anders, was mich glauben ließ, dass die von PHP generierte XLSX-Datei das OpenOffice- oder LibreOffice-Format verwendet, das DHL nicht verwendet hat.

Gibt es eine Möglichkeit, dieses Problem zu beheben? Eine Idee, die ich habe, ist, einfach die PHP XLSXWriter-Funktionalität abzulegen und die Daten einfach als Rohtextdatei mit Tab-getrennten Daten zu speichern (die DHL auch akzeptiert). schien

$filename = "test.xlsx"; header('Access-Control-Allow-Origin: mysite.com'); header('Content-disposition: attachment; filename="'.XLSXWriter::sanitize_filename($filename).'"'); header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate'); header('Pragma: public');

$rows = array(
     array('Pick-up Account Number', 'Sales Channel', 'Shipment Order ID', 'Tracking Number', 'Shipping Service Code', 'Company',      'Consignee Name',            'Address Line 1',    'Address Line 2',    'Address Line 3',    'City',     'State',      'Postal Code',     'Destination Country Code',  'Phone Number',   'Email Address',  'Shipment Weight (g)', 'Length (cm)', 'Width (cm)', 'Height (cm)', 'Currency Code', 'Total Declared Value',  'Incoterm', 'Freight', 'Is Insured', 'Insurance', 'Is COD', 'Cash on Delivery Value', 'Recipient ID', 'Recipient ID Type', 'Duties', 'Taxes', 'Workshare Indicator', 'Shipment Description', 'Shipment Import Description', 'Shipment Export Description', 'Shipment Content Indicator', 'Content Description', 'Content Import Description', 'Content Export Description', 'Content Unit Price', 'Content Origin Country', 'Content Quantity', 'Content Weight (g)', 'Content Code', 'HS Code', 'Content Indicator', 'Remarks', 'Shipper Company', 'Shipper Name', 'Shipper Address1', 'Shipper Address2', 'Shipper Address3', 'Shipper City', 'Shipper State', 'Shipper Postal Code', 'Shipper CountryCode', 'Shipper Phone Number', 'Shipper Email address', 'Return Company', 'Return Name', 'Return Address Line 1', 'Return Address Line 2', 'Return Address Line 3', 'Return City', 'Return State', 'Return Postal Code', 'Return Destination Country Code', 'Return Phone Number', 'Return Email Address', 'Service1', 'Service2', 'Service3', 'Service4', 'Service5', 'Grouping Reference1', 'Grouping Reference2', 'Customer Reference 1', 'Customer Reference 2',),    
     array('123456789',    '',     $order_id,    '',     'PPS',      $order->shipping_company,  $order->shipping_first_name.' '.$order->shipping_last_name,  $order->shipping_address_1,  $order->shipping_address_2,  $order->shipping_address_3,  $order->shipping_city, $order->shipping_state,   $order->shipping_postcode,  $order->shipping_country,  $order->billing_phone, $order->billing_email, '160',     '18',   '13',   '6',   'AUD',    '70',      '',   '',   '',    '',    '',   '',       '',    '',      '',   '',   '',      'Printer Cartridge', '',        '',        '',        'Printer Cartridge', '',        '',        '70',     'AU',      '1',    '',      'TEST_2214', '',   '',      '',   '',     '',    '',     '',     '',     '',    '',     '',      '',      '',      '',       '',     '',    '',       '',       '',       '',    '',    '',      '',         '',      '',      '',   '',   '',   '',   '',   '',      '',      '',      '',),    
    ); 

    $writer = new XLSXWriter(); 
    $writer->setAuthor('TEST'); 

    foreach($rows as $row) 
    $writer->writeSheetRow('Sheet1', $row); 
    $writer->writeToStdOut();` 

Als Hinweis, der DHL-Server über die Daten in der Zeile zu beschweren ‚PPS‘ enthält:

Hier ein kurzes Beispiel der primären Funktion in meinem Code ist .

Danke.

Antwort

0

gelöst durch eine Registerkarte Schreiben separierte Datei:

header("Content-type: text/csv"); 
    header("Content-Disposition: attachment; filename=example.txt"); 
    header("Pragma: no-cache"); 
    header("Expires: 0"); 

    $rows = array(
    array('Pick-up Account Number', 'Sales Channel', 'Shipment Order ID', 'Tracking Number', 'Shipping Service Code', 'Company',      'Consignee Name',            'Address Line 1',    'Address Line 2',    'Address Line 3',    'City',     'State',      'Postal Code',     'Destination Country Code',  'Phone Number',   'Email Address',  'Shipment Weight (g)', 'Length (cm)', 'Width (cm)', 'Height (cm)', 'Currency Code', 'Total Declared Value',  'Incoterm', 'Freight', 'Is Insured', 'Insurance', 'Is COD', 'Cash on Delivery Value', 'Recipient ID', 'Recipient ID Type', 'Duties', 'Taxes', 'Workshare Indicator', 'Shipment Description', 'Shipment Import Description', 'Shipment Export Description', 'Shipment Content Indicator', 'Content Description', 'Content Import Description', 'Content Export Description', 'Content Unit Price', 'Content Origin Country', 'Content Quantity', 'Content Weight (g)', 'Content Code', 'HS Code', 'Content Indicator', 'Remarks', 'Shipper Company', 'Shipper Name', 'Shipper Address1', 'Shipper Address2', 'Shipper Address3', 'Shipper City', 'Shipper State', 'Shipper Postal Code', 'Shipper CountryCode', 'Shipper Phone Number', 'Shipper Email address', 'Return Company', 'Return Name', 'Return Address Line 1', 'Return Address Line 2', 'Return Address Line 3', 'Return City', 'Return State', 'Return Postal Code', 'Return Destination Country Code', 'Return Phone Number', 'Return Email Address', 'Service1', 'Service2', 'Service3', 'Service4', 'Service5', 'Grouping Reference1', 'Grouping Reference2', 'Customer Reference 1', 'Customer Reference 2',),    
    array('123456789',    '',     $order_id,    '',     'PPS',      $order->shipping_company,  $order->shipping_first_name.' '.$order->shipping_last_name,  $order->shipping_address_1,  $order->shipping_address_2,  $order->shipping_address_3,  $order->shipping_city, $order->shipping_state,   $order->shipping_postcode,  $order->shipping_country,  $order->billing_phone, $order->billing_email, '160',     '18',   '13',   '6',   'AUD',    '70',      '',   '',   '',    '',    '',   '',       '',    '',      '',   '',   '',      'Printer Cartridge', '',        '',        '',        'Printer Cartridge', '',        '',        '70',     'AU',      '1',    '',      'TEST_2214', '',   '',      '',   '',     '',    '',     '',     '',     '',    '',     '',      '',      '',      '',       '',     '',    '',       '',       '',       '',    '',    '',      '',         '',      '',      '',   '',   '',   '',   '',   '',      '',      '',      '',),    
); 

    foreach ($rows as $arr) 
    { 
     $row = implode("\t", $arr); 
     $row.="\n"; 
     echo $row; 
    } 

Dies erzeugt die richtigen Daten und DHL übernimmt es. Vielen Dank.