WordPress.org

Ready to get started?Download WordPress

Forums

Websimon Tables
export multiline field to .csv (1 post)

  1. cvermeir
    Member
    Posted 1 year ago #

    if u have multiline field cells u want to export to .csv

    /*
    Export table to .csv file
    */
    
    if (isset($_GET['action']) && $_GET['action'] == 'export_table_content') {
    	$nonce = $_GET['_wpnonce'];
    	if ( empty($_GET) || !wp_verify_nonce($nonce, 'export-table-content' ) )
    	{
    		print 'Sorry, you cannot process data this way.';
    		exit;
    	}
    	else
    	{
    		$output = '';
    		$exportArray = array();
    		$id = $_GET['export_id'];
    		$name = $_GET['exports_name'];
    		global $wpdb;
    		$table_name = $wpdb->prefix . "websimon_tables";
    		$results = $wpdb->get_results("SELECT headlines, content FROM $table_name WHERE id='$id'");
    
    		foreach ($results as $result)
    		{
    
    			//add headlines
    			$headArray = explode('[-|-]', $result->headlines);
    			$count = 0;
    			foreach ($headArray as $elem)
    			{
    				if ($count == 0)
    				{
    					$cell = str_replace(array('\r\n','\r','\n'), '\n', $cell);
    					$output .= '"'. utf8_decode($elem).'"';
    				}
    				else
    				{
    					$cell = str_replace(array('\r\n','\r','\n'), '\n', $cell);
    					$output .= ';"' . utf8_decode($elem).'"';
    				}
    				$count++;
    			}
    			$output .= "\r\n";
    
    			//add content
    			$bodyArray = explode('[-%row%-]' , $result->content);
    			foreach ($bodyArray as $elem)
    			{
    				$count = 0;
    				$rowArray = explode('[-%cell%-]', $elem);
    				foreach ($rowArray as $cell)
    				{
    					if ($count == 0)
    					{
    						$cell = str_replace(array('\r\n','\r','\n'), '\n', $cell);
    						$output .= '"'. utf8_decode($cell).'"';
    
    					}
    					else
    					{
    						$cell = str_replace(array('\r\n','\r','\n'), '\n', $cell);
    						$output .= ';"' . utf8_decode($cell).'"';
    					}
    					$count++;
    				}
    				$output .= "\r\n";
    			}
    		}
    
    		$sitename = get_bloginfo( 'url' );
    		$filename = 'exports-table-' . $name . '.csv';
    
    		header( 'Content-Description: File Transfer' );
    		header( 'Content-Disposition: attachment; filename=' . $filename );
    		header( 'Content-Type: text/csv; charset=' . get_option( 'blog_charset' ), true );
    		echo $output;
    		exit;
    	}
    }

    http://wordpress.org/extend/plugins/websimon-tables/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic