Zum Inhalt springen

Powermail - Export als xls - Problem mit Charset

Erstellt am 8. Juli 2009 · 5 Antworten · letzte Antwort am 29. September 2010

Tags: Powermail, Import & Export, Frage

dabjoern ·

Hallo Leute,

ich habe hier eine Website, bei der das Charset und die Datenbank auf UTF-8 gestellt sind. Meine Redakteure wollen sich powermail Datensätze mit dem dazugehörigen Modul als xls Datei exportieren. In der Exportdatei sind Umlaute vorhanden, die allerdings nicht richtig dargestellt werden. So wird aus Prämie "Prämie". Kann mir da jemand helfen?

Edit: Ich habe mir mal die Variable $this->outputEncoding (class.tx_powermail_export.php) ausgeben lassen. Sie zeigt utf-8 an. Warum stimmt der Header trotzdem nicht?

Edit2: Im HTML Export stimmen die Chars allerdings. Im xls und csv nicht... Sehr komisch.

Viele Grüße, dabjoern

dabjoern ·

Hallo,

also das Thema ist echt difizil. Ich habe mal die Zeile 266 geändert und dort utf8_decode eingefügt:

if ($key != 'uid') { // static values
if ($export == 'csv') { // CSV only
$table .= '"'.utf8_decode($value).'"'.$this->seperator;
} else { // HTML and EXCEL only
$table .= '<td><b>'.utf8_decode($value).'</b></td>';
}

Nun erhalte ich folgendes Ergebnis:
xls: Header und Content passen,
csv: Header passt, Content nicht,
HTML: Header passt nicht, Content passt.

Also habe ich den Code weiter umgestellt:

if ($key != 'uid') { // static values
if ($export == 'csv') { // CSV only
$table .= '"'.utf8_decode($value).'"'.$this->seperator;
} elseif ($export == 'table') { // HTML only
$table .= '<td><b>'.$value.'</b></td>';
} else { // EXCEL only
$table .= '<td><b>'.utf8_decode($value).'</b></td>';
}

Jetzt passen die Header. Im csv passt der Content noch nicht. Was machen wir da jetzt?

Viele Grüße, dabjoern

comix ·

Bin gerade am genau demselben Problem

Force Charset habe ich auf utf-8 eingestellt und im setup ist das metaCharset auch auf UTF-8 eingestellt.

Wenn ich die CSV exportieren möchte erhalte ich zerschossene Umlaute.

mferber ·

Ich habe hier das gleiche Problem (Powermail 1.5). Interessanterweise funktioniert der Export über das Frontend einwandfrei, mit cronjob.php (cli) sind die Umlaute in der Exeltabelle "zerschossen".

Für jeden Tipp bin ich dankbar. utf-8 ist - soweit ich das feststellen kann- überall gesetzt.

Gruß
Michael

*  Copyright notice
*
*  (c) 2010 Alex Kellner <alexander.kellner@einpraegsam.net>
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

 
 // Defining circumstances for CLI mode:
define('TYPO3_cliMode', TRUE);
define('PATH_thisScript', $_SERVER['SCRIPT_FILENAME']);
if (!PATH_thisScript) define('PATH_thisScript', $_ENV['_'] ? $_ENV['_'] : $_SERVER['_']);
require(dirname(PATH_thisScript) . '/conf.php');
require(dirname(PATH_thisScript) . '/'.$BACK_PATH.'init.php');
require_once(PATH_t3lib . 'class.t3lib_admin.php');
require_once(PATH_t3lib . 'class.t3lib_cli.php');
require_once(PATH_typo3 . 'template.php');
require_once(PATH_t3lib . 'class.t3lib_htmlmail.php');
require_once('../mod1/class.tx_powermail_export.php'); // include div functions
require_once(t3lib_extMgm::extPath('lang', 'lang.php')); // include lang class
$LANG = t3lib_div::makeInstance('language');
$LANG->init('en');
#$LANG->includeLLFile(dirname(dirname(PATH_thisScript)) . '/mod1/locallang.xml');
$pid = intval($_GET['pid']);
$content = $file = '';

if ($pid > 0) { // if Page id given from GET param
	
	// tsconfig
	$tmp_defaultconfig = array (
		'time' => 86400, // default setting 1 day
		'body' => 'See XLS file in attachment', // default body
		'subject' => 'New powermail export email', // default subject
		'email_receiver' => 'meine@mailadresse', // default: no receiver mail
		'email_receiver_cc' => '', // default: no cc mail
		'email_sender' => 'noreply@einpraegsam.net', // default sender address
		'sender' => 'powermail' // default sender name
	);
	$tmp_tsconfig = t3lib_BEfunc::getModTSconfig($pid, 'tx_powermail_cli'); // get whole tsconfig from backend
	$tsconfig = array_merge((array) $tmp_defaultconfig, (array) $tmp_tsconfig['properties']['exportmail.']); // get tsconfig from powermail cli
	
	if (t3lib_div::validEmail($tsconfig['email_receiver'])) { // if receiver email is set

		// Generate the xls file
		$export = t3lib_div::makeInstance('tx_powermail_export');
		$export->default_start = strftime('%Y-%m-%d %H:%M', (time() - $tsconfig['time'])); // current time minus delta
		$export->default_end = strftime('%Y-%m-%d %H:%M', time()); // current time (like 2010-01-01 00:00)
		$file = t3lib_div::getFileAbsFileName($export->main('email', $pid, $LANG));
		
		if (!empty($file)) { // if file is not empty
			
			// Generate the mail
			$htmlMail = t3lib_div::makeInstance('t3lib_htmlmail'); // New object: TYPO3 mail class
			$htmlMail->start(); // start htmlmail
			$htmlMail->recipient = $tsconfig['email_receiver']; // main receiver
			$htmlMail->recipient_copy = $tsconfig['email_receiver_cc']; // cc
			$htmlMail->subject = $tsconfig['subject']; // mail subject
			$htmlMail->from_email = $tsconfig['email_sender']; // sender email
			$htmlMail->from_name = $tsconfig['sender']; // sender name
			$htmlMail->addAttachment($file); // add attachment
			$htmlMail->addPlain($tsconfig['body']); // add plaintext
			$htmlMail->setHTML($htmlMail->encodeMsg($tsconfig['body'])); // html format if active via constants
			$htmlMail->setHeaders();
			$htmlMail->setContent();
			if ($htmlMail->sendTheMail()) {
				$content .= 'Mail successfully sent';
			} else {
				$content .= 'Powermail Error in sending mail';
			}
	
		} else {
			$content .= 'There are no mails to export in the last ' . $tsconfig['time'] . ' seconds in pid ' . $pid;
		}
	} else {
		$content .= 'Powermail Error: No or invalid receiver Email address (maybe you forget to set the receiver email in the tsconfig of page ' . $pid 

. ')';
	}

} else {
	$content .= 'Powermail Error: No pid given (open this script with pid like ...cronjob.php?pid=1)';
}

echo $content;
?>