Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QUESTION Building a form + export data
#4
I built a Facebook scraping tool a while back. Nothing special, except I exported the data in Excel XML (SpreadsheetML). It worked really well, you can find more info here: https://msdn.microsoft.com/en-us/library...e.11).aspx. You do need a local XML schema file so that Excel can properly parse it; for an example of how all of this should work: see below the JS I used to convert data to Excel XML, and in attachment the XML scheme.

Code:
    var options = {
 appName: 'FB Wall Scraper',
 docTitle: fbTimelineScraper._pageOwner + ' Facebook Posts',
 cols: [
   {header: 'Date', width: 600},
   {header: 'Text', width: 100},
   {header: 'Links', width: 40},
   {header: 'Likes', width: 40},
   {header: 'Shares', width: 70},
   {header: 'Comments', width: 90},
   {header: 'Hashtags', width: 50}
 ]
}, wnd, data = fbTimelineScraper.get(), type,
output = '<?xml version="1.0"?>'
 + '<?mso-application progid="Excel.Sheet"?>'
 + '\n<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"'
 + '\n\txmlns:o="urn:schemas-microsoft-com:office:office"'
 + '\n\txmlns:x="urn:schemas-microsoft-com:office:excel"'
 + '\n\txmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"'
 + '\n\txmlns:html="http://www.w3.org/TR/REC-html40">'
 + '\n\t<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">'
 + '\n\t\t<Title>' + options.docTitle + '</Title>'
 + '\n\t\t<Author>' + options.author + '</Author>'
 + '\n\t\t<LastAuthor>' + options.author + '</LastAuthor>'
 + '\n\t</DocumentProperties>'
 + '\n\t<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">'
 + '\n\t\t<ProtectStructure>False</ProtectStructure>'
 + '\n\t\t<ProtectWindows>False</ProtectWindows>'
 + '\n\t</ExcelWorkbook>'
 + '\n\t<Styles>'
 + '\n\t\t<Style ss:ID="xl1"><Alignment ss:WrapText="0"/></Style>'
 + '\n\t\t<Style ss:ID="xl2"><Font ss:Color="blue" ss:Underline="Single"/></Style>'
 + '\n\t\t<Style ss:ID="xl3"><Font ss:Color="black" ss:Bold="1"/></Style>'
 + '\n\t\t<Style ss:ID="xl4"><Font ss:Color="white" ss:Underline="None" ss:Size="14"/>'
 + '<Alignment ss:Vertical="Center"/><Interior ss:Pattern="Solid" ss:Color="SlateGray"/></Style>'
 + '\n\t\t<Style ss:ID="xl5"><Font ss:Color="white" ss:Underline="None" ss:Size="10"/><Alignment ss:Vertical="Top" ss:Horizontal="Center"/>'
 + '<Interior ss:Pattern="Solid" ss:Color="SlateGray"/></Style>'
 + '\n\t</Styles>'
 + '\n\t<Worksheet ss:Name="Facebook Posts">'
 + '\n\t\t<Table>'
 + '\n\t\t\t<Column ss:Width="' + options.cols[6].width + '"/>'
 + '\n\t\t\t<Column ss:StyleID="xl1" ss:Width="' + options.cols[0].width + '"/>'
 + '\n\t\t\t<Column ss:StyleID="xl2" ss:Width="' + options.cols[1].width + '"/>'
 + '\n\t\t\t<Column ss:Width="' + options.cols[2].width + '"/>'
 + '\n\t\t\t<Column ss:Width="' + options.cols[3].width + '"/>'
 + '\n\t\t\t<Column ss:Width="' + options.cols[4].width + '"/>'
 + '\n\t\t\t<Column ss:Width="' + options.cols[5].width + '"/>'
 + '\n\t\t\t<Row ss:Height="30" ss:StyleID="xl4"><Cell ss:MergeAcross="1"><Data ss:Type="String">' + options.docTitle + '</Data></Cell>'
 + '<Cell ss:MergeAcross="2"><Data ss:Type="String">' + options.appName + '</Data></Cell></Row>'
 + '\n\t\t\t<Row ss:StyleID="xl4"><Cell ss:MergeAcross="1"><Data ss:Type="String"></Data></Cell>'
 + '<Cell ss:MergeAcross="2" ss:StyleID="xl5"><Data ss:Type="String">by ' + options.author + '</Data></Cell></Row>'
 + '\n\t\t\t<Row></Row><Row>'
 + '\n\t\t\t\t<Cell ss:StyleID="xl3"><Data ss:Type="String">' + options.cols[6].header + '</Data></Cell>'
 + '\n\t\t\t\t<Cell ss:StyleID="xl3"><Data ss:Type="String">' + options.cols[0].header + '</Data></Cell>'
 + '\n\t\t\t\t<Cell ss:StyleID="xl3"><Data ss:Type="String">' + options.cols[1].header + '</Data></Cell>'
 + '\n\t\t\t\t<Cell ss:StyleID="xl3"><Data ss:Type="String">' + options.cols[2].header + '</Data></Cell>'
 + '\n\t\t\t\t<Cell ss:StyleID="xl3"><Data ss:Type="String">' + options.cols[3].header + '</Data></Cell>'
 + '\n\t\t\t\t<Cell ss:StyleID="xl3"><Data ss:Type="String">' + options.cols[4].header + '</Data></Cell>'
 + '\n\t\t\t\t<Cell ss:StyleID="xl3"><Data ss:Type="String">' + options.cols[5].header + '</Data></Cell>'
 + '\n\t\t\t</Row>';

for (var i = 0; i < data.length; i++) {
 output += '\n\t\t\t<Row>';
 for (prop in data[i]) {
   type = parseInt(data[i][prop]) === data[i][prop] ? 'Number' : 'String';
   if (prop !== 'links') {
     output += '\n\t\t\t\t<Cell><Data ss:Type="' + type + '">' + data[i][prop] + '</Data></Cell>';
   } else {
     output += '\n\t\t\t\t<Cell';-
     if (data[i][prop] !== '') {
       output += ' ss:HRef="' + data[i][prop] + '"><Data ss:Type="String">' + data[i][prop];
     } else {
       output += '><Data ss:Type="String">';
     }
     output += '</Data></Cell>';
   }
 }
 output += '</Row>';
}
output += '\n\t\t</Table>\n\t</Worksheet>\n</Workbook>';

Note: I'm not sure this code was the latest version, but it should give you enough of an idea of how to make it work.


Attached Files
.zip   xmlSchema.zip (Size: 671 bytes / Downloads: 1)
Reply


Messages In This Thread
Building a form + export data - by colorfill - 2015-08-13, 23:28:05
RE: Building a form + export data - by shawn_a - 2015-08-13, 23:37:25
RE: Building a form + export data - by colorfill - 2015-08-13, 23:51:15
RE: Building a form + export data - by bluzer - 2015-08-28, 05:13:27
RE: Building a form + export data - by Tyblitz - 2015-08-14, 19:25:34



Users browsing this thread: 2 Guest(s)