We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6955 ☆ A M B ☆
    • 147 Posts
    I have a file - which is a one page softball statistics page - and I would like to convert it for a webpage where I can import it or convert it somehow enter it into MODX. One option would be to create a table and then manually type in the data into each cell. But I would like to simplify it if possible and import it. Any suggestions or ideas?

    Thanks!
      Billy Koch
      Follow me on Twitter: @DefKoch
      Skype: billyk0ch
      • 19889
      • 616 Posts
      did you look into Google Docs yet
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Create a table, then use your control panel’s phpMyAdmin (or whatever mysql client it offers) to import the xls file.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 6955 ☆ A M B ☆
          • 147 Posts
          Google Docs - that is what Im currently using but for some reason its looking kinda funny.

          I’ll try that.

            Billy Koch
            Follow me on Twitter: @DefKoch
            Skype: billyk0ch
            • 10487 MODX Staff
            • 1,535 Posts
            You could, if you don’t mind getting your hands dirty a little with PHP, output the spreadsheet as a CSV and then use PHP’s native CSV functions to import the data into a database table and use a basic snippet to output the HTML table in whatever format you need on your site.

            The example here gives you 80% of the CSV import code you’ll need: http://uk3.php.net/manual/en/function.fgetcsv.php

            All you have to do to that is, on reading each row, have a query to update the database. If you don’t need to keep historical stats, you could have a query before the CSV loop to truncate the table. Then, use the $modx->db->insert() method to put each row in the database.

            The snippet for the table is as simple as grabbing all the rows from the database table, looping through and outputting your HTML table row in the desired format.
              Garry Nutting
              Senior Developer
              MODX, LLC

              Email: [email protected]
              Twitter: @garryn
              Web: modx.com
              • 4172
              • 5,888 Posts
              you can also try this simple class. Make a form with textarea name="csvimport".
              Copy and paste your excel-cells with fieldnames in first row into this textarea.


              <?php
              class calcimporter
              {
              
                  function calcimporter($importfields){
                  	$this->importfields=$importfields;
              		$this->errorfields = array ();
              		$this->tab_replacement="</td><td>";//should be something what is not in your inputstring
                  }
              
                  function tabs_to_array($inputstring)
                  {
                      
                      
                      //replace all tabs with end-cell, begin-cell
                      $input = preg_replace("/\t/", $this->tab_replacement, $inputstring);
              
                      //split the list on linebreaks
                      $rows = preg_split("/\r\n/", $input);
              
                      //make Array from lines
                      $output = "";
                      foreach ($rows as $index=>$row)
                      {
                          if ($index == 0)
                          {
                              $this->tablefields = explode($this->tab_replacement, $row);
                          } else
                          {
                              $tablerow = array ();
                              $rowarray = array ();
                              if (strlen($row) > 0)
                              {
                                  $rowarray = explode($this->tab_replacement, $row);
                                  foreach ($rowarray as $key=>$value)
                                  {
                                      if (in_array($this->tablefields[$key], $this->importfields))
                                      {
                                          $tablerow[$this->tablefields[$key]] = $value;
                                      }
                                      else
                                      {
                                          if (!in_array($this->tablefields[$key], $this->errorfields))
                                          {
                                              $this->errorfields[] = $this->tablefields[$key];
                                              unset ($this->tablefields[$key]);
                                          }
              
                                      }
              
                                  }
                                  $tablerows[] = $tablerow;
                              }
                          }
                      }
                      //echo'<pre>'.print_r($tablerows,true).'</pre>';
                      return ($tablerows);
                  }
              }
              
              //print_r($_POST);
              
              //$bloxdatas['formstatus'] = '1';
              
              $importer = new calcimporter($importfields);//fields as array which you want to import
              if ( isset ($_POST['csvimport']))
              {
                  $rows = $importer->tabs_to_array($_POST['csvimport']);//don't forget to escape your imprted values
                  
              	//do what you want with imported array, insert or update tables, output as html....
              
              }
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 37272
                • 216 Posts
                You might try one of these two related utilities: wikiCalc amd SocialCalc.

                I just copy/paste the Excel table’s contents to wikicalc, and with a few more clicks (to add borders, colours, etc.), it is done. Instead of just linking to the generated webpage, you could, of course, instead copy the generated output to your webpage. It takes me about 5 minutes to complete the whole task.
                  • 47243
                  • 30 Posts
                  Hi,
                  I had a slightly different need, wanted to update my data in a google spreadsheet and have modx retrieve those data and put them in placeholders that I place in my template.
                  based on https://gist.github.com/pamelafox/770584

                  So here is the snippet , called it GoogleSpreadsheet :
                  <?php
                  // Google spreadsheet must be published
                  // Looks like:
                  //	id-fr	id-en	(name)			knowledge	experience	prospective
                  	72		112		wordpress 		70			75			85
                  	81		113		css		 		50			15			30
                  
                  
                  $myGoogleSpreadsheetKey = $modx->getOption('myGoogleSpreadsheetKey', $scriptProperties, '');
                  $gid = $modx->getOption('gid', $scriptProperties, '0');
                  $cultureKey = $modx->getOption('cultureKey', $scriptProperties, 'fr');
                  $gdocRow = $modx->getOption('gdocRow', $scriptProperties, '1');
                  $gdocColumns = $modx->getOption('gdocColumns', $scriptProperties, '');
                  
                  $columns = explode(',',$gdocColumns);
                  $url = 'http://spreadsheets.google.com/feeds/list/' . $myGoogleSpreadsheetKey . '/'. $gid .'/public/values?alt=json';
                  $file= file_get_contents($url);
                  $json = json_decode($file);
                  $rows = $json->{'feed'}->{'entry'};
                  
                  foreach($rows as $row) {
                  	// define cultureKey : because I use 2 languages, when translating I need the data to load also for my translated language
                  	if($cultureKey =='fr') $id = $row->{'gsx$id-fr'}->{'$t'};
                  	if($cultureKey =='en') $id = $row->{'gsx$id-en'}->{'$t'};
                  
                  	if($id == $gdocRow){
                  		foreach($columns as $idx=>$column) {
                  			$modx->setPlaceholder('column.name.'.($idx+1),$column);
                  			$modx->setPlaceholder('column.value.'.($idx+1),$row->{'gsx$'.$column}->{'$t'});
                  		}	
                  	        break;
                  	}
                  }


                  and then use it like this

                  [[GoogleSpreadsheet? &key=`[[++myGoogleSpreadsheetKey]]` &gid=`[[++myGoogleSpreadsheetGid.myServices]]` &cultureKey=`[[++cultureKey]]` &gdocRow=`[[+id]]` &gdocColumns=`knowledge,experience,prospective`]]
                  
                    <div class="skillbar clearfix " data-percent="[[+column.value.1]]%">
                  	<div class="skillbar-title"><span>[[%[[+column.name.1]]? &namespace=`my_site` &topic=`skillbars`]]</span></div>
                  	<div class="skillbar-bar"></div>
                  	<div class="skill-bar-percent">[[+column.value.1]]%</div>
                    </div>
                  
                    <div class="skillbar clearfix " data-percent="[[+column.value.2]]%">
                  	<div class="skillbar-title"><span>[[%[[+column.name.2]]? &namespace=`my_site` &topic=`skillbars`]]</span></div>
                  	<div class="skillbar-bar"></div>
                  	<div class="skill-bar-percent">[[+column.value.2]]%</div>
                    </div>
                  
                    <div class="skillbar clearfix " data-percent="[[+column.value.3]]%">
                  	<div class="skillbar-title"><span>[[%[[+column.name.3]]? &namespace=`my_site` &topic=`skillbars`]]</span></div>
                  	<div class="skillbar-bar"></div>
                  	<div class="skill-bar-percent">+[[+column.value.3]]%</div>
                    </div>


                  Notice I used context settings to define my spreadsheet key and sheet gid (which is the sheet index, you can get it when editing your google doc)
                  The placeholders ares generated depending of the content of gdocColumnswhich is separated by commas.
                  The placeholders have index in the same order as the list of gdocColumns, it can output the name and the value


                  The id-fr and id-en are the id of the resources which will output the data.
                  [[+id]] needs to be replaced by your ressource id. As this code is a chunk, I call it in another chunk like this :
                  [[$mySkillbars.myServices? &id=`[[*id]]`]]


                  and inside this chunk I have the chunk I posted.

                  If you use it directly in template, you use [[*id]] for &gdocRow [ed. note: robotpapier last edited this post 12 years, 4 months ago.]
                    • 3749
                    • 24,544 Posts
                    Quote from: garryn at Mar 18, 2010, 12:03 PM
                    You could, if you don't mind getting your hands dirty a little with PHP, output the spreadsheet as a CSV and then use PHP's native CSV functions to import the data into a database table and use a basic snippet to output the HTML table in whatever format you need on your site.

                    The example here gives you 80% of the CSV import code you'll need: http://uk3.php.net/manual/en/function.fgetcsv.php

                    All you have to do to that is, on reading each row, have a query to update the database. If you don't need to keep historical stats, you could have a query before the CSV loop to truncate the table. Then, use the $modx->db->insert() method to put each row in the database.

                    The snippet for the table is as simple as grabbing all the rows from the database table, looping through and outputting your HTML table row in the desired format.

                    I recommend this method. I recently used it to import a user list and it went very smoothly. It's also nice that if you need to make minor changes to the data, you can edit the CSV file with a text editor.
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 36446
                      • 184 Posts
                      Quote from: BobRay at May 02, 2014, 11:33 AM
                      Quote from: garryn at Mar 18, 2010, 12:03 PM
                      You could, if you don't mind getting your hands dirty a little with PHP, output the spreadsheet as a CSV and then use PHP's native CSV functions to import the data into a database table and use a basic snippet to output the HTML table in whatever format you need on your site.

                      The example here gives you 80% of the CSV import code you'll need: http://uk3.php.net/manual/en/function.fgetcsv.php

                      All you have to do to that is, on reading each row, have a query to update the database. If you don't need to keep historical stats, you could have a query before the CSV loop to truncate the table. Then, use the $modx->db->insert() method to put each row in the database.

                      The snippet for the table is as simple as grabbing all the rows from the database table, looping through and outputting your HTML table row in the desired format.

                      I recommend this method. I recently used it to import a user list and it went very smoothly. It's also nice that if you need to make minor changes to the data, you can edit the CSV file with a text editor.

                      I'm also looking for something that can import xls lists with user account data. Ideally it would be in a Component that can handle my xls file and import it to predifiened user groups. Any hints are welcome
                        https://www.beautyislife-shop.de - premium make-up!
                        https://www.topsterne.de - sell it here!
                        ---------------------------------------------------------