How can I download to Excel? - excel

I'd like to go about offering a "download to excel" functionality for several different sets of data available on different parts of my coldfusion website. I'm using coldfusion and would love to use freely available custom tags / libraries that can help me accomplish this instead of coding it all myself from scratch. I've been pointed to cflib.org but am not sure how to get started. Anyone have any ideas, comments, or resources about downloading coldfusion website data to excel?

An approach that I have used in the past for an intranet with a load of tabular statistical data is to take advantage of the fact that Excel can read HTML.
On pages that I intend to provide Excel links for, I write out the core table as HTML to a file and include a link to that file in the rendered page. You can then serve this page with an .xls extension, use meta headers or even use an intermediary page with CFCONTENT in order to have your browser fire up Excel to display the content.
This approach can be extended for an arbitrary number of tables per page. You would have to write a tag to contain the table which will then take care of writing the file and supplying the download link for all HTML content contained within.
Sorry for the lack of example code. If my description of the process has left you scratching your head then I'll provide some examples for you.

You can also use an html table, as in:
<cfquery name="data" datasource="whatever">
...
</cfquery>
<cfheader name="Content-Disposition" value="inline; filename=fileName.xls">
<cfcontent type="application/x-msexcel" reset="true">
<table border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<td>Col1</td>
<td>Col2</td>
</tr>
</thead>
<tbody>
<cfoutput query="data">
<tr>
<td>#data.Col1#</td>
<td>#data.Col2#</td>
</tr>
</cfoutput>
</tbody>
</table>
hth,
larry

If you are on ColdFusion 9, you can always use cfspreadsheet:
http://www.cfquickdocs.com/cf9/#cfspreadsheet
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WS434C35B0-279B-4051-A61B-D84B5D76189C.html

Building on #Ciaran Archer's answer, I usually use CSV to accomplish this, which Excel will open up from the web if installed on a client's PC. Assuming the data you're working with is coming out of a database, use the QueryToCSV() from Ben Nadel's site as such:
<cfquery name="data" datasource="">
...
</cfquery>
<cfinclude template="fun_queryToCSV.cfm">
<cfheader name="Content-Disposition" value="filename=my-file-name.xls">
<cfcontent type="test/csv" reset="true">
<cfoutput>#querytoCSV(data)#</cfoutput>
The "reset" on cfcontent clears the response buffer so that the only thing inside of it is what comes after. Alternately, if you already have the data as file, cfcontent has a "file" attribute that will serve its contents up directly.

In the end, we used the Query2Excel function from cflib.org, and modified it slightly to suit our specific needs.

For those on Coldfusion 9+ and able to use cfspreadsheet, you can leverage SpreadsheetReadBinary() to make the spreadsheet downloadable without having to write the spreadsheet to a file first.

Related

How to represent a table using excel data when clicked on a location in Google Earth Pro?

I am building a map on Google Earth Pro to visualize political workers' data in a specific area. I have designed the basic elements in kml but the data used is hard coded in the kml file itself. I want to automate the process so that anyone can change the data in the master excel sheet and it gets reflected on Google Earth because the booth workers keep changing in every area for every election.
How can I fetch data from an excel sheet and represent it in a tabular format on Google Earth?
Sharing a snippet from the kml file:
`<Placemark>
<name>1,Dehradun</name>
<description><[CDATA[<div><b>PARTY WORKERS</b><br></div>
<table border="1">
<tbody>
<tr><br></tr><tr><td><b>SNO</b><br></td><td><b>NAME</b><br></td><td><b>CONTACT</b><br></td><td><b>COMMENTS</b><br></td><td><b>WORK ASSIGNED</b><br></td></tr>
<tr><td>1<br></td><td>Member1<br></td><td>9917973599<br></td><td>GOOD WORKER<br></td><td>BOOTH MGMT<br></td></tr>
<tr><td>2<br></td><td>Member2<br></td><td>8958644329<br></td><td>LAZY<br></td><td>MAKE PHONE CALLS<br></td></tr>
<tr><td>3<br></td><td>Member3<br></td><td>7894512547<br></td><td>SMART<br></td><td>DATA MGMT<br></td></tr>
</tbody>
</table>
<div><br></div><div><br></div><div><b>INFLUENCERS</b><br></div>
<table border="1">
<tbody>
<tr><br></tr><tr><td><b>SNO</b><br></td><td><b>NAME</b><br></td><td><b>CONTACT</b><br></td><td><b>COMMENTS</b><br></td><td><b>WORK ASSIGNED</b><br></td></tr>
<tr><td>1<br></td><td>Influencer1<br></td><td>9917973599<br></td><td>HIGH INFLUENCE<br></td><td>BOOTH MGMT<br></td></tr>
<tr><td>2<br></td><td>Influencer2<br></td><td>8958644329<br></td><td>ENTIRE BOOTH<br></td><td>NO WORK ASSIGNED<br></td></tr>
<tr><td>3<br></td><td>Influencer3<br></td><td>7894512547<br></td><td>SMART MAN<br></td><td>DATA MGMT<br></td></tr>
</tbody>
</table></description>
<styleUrl>#__managed_style_053287BE6F14D9C2C7B8</styleUrl>
<Point>
<coordinates>78.032188,30.316496,0</coordinates>
</Point>
</Placemark>`
Tried Spreadsheet Mapper V3.2 earlier but it doesn't seem to work now. Found out online that it has been discontinued.
I want this kind of output but it should come from an excel sheet instead of being hard coded:
enter image description here
In order to update a KML file from a spreadsheet, you'll need a server of some kind that can re-generate the KML when the spreadsheet is updated (like Spreadsheet Mapper used to do using Apps Scripts). This is not something that is "built in" to Google Earth, so there's not a simple solution.
That said, Google My Maps recently launched a feature where you can update a layer in your MyMap based on changing data in a spreadsheet. For info see this medium post:
https://medium.com/google-earth/new-my-maps-features-make-it-easier-to-share-maps-update-datasets-and-more-965ed0b48875
and this documentation page:
https://support.google.com/mymaps/answer/3024836
I'm not if it will be easy or even possible to update the data behind your custom balloon layout, but it's probably worth a shot. If you get it to work, then you can either have your users view the data directly in My Maps, or you can try getting the NetworkLink KML for the MyMap, and viewing that in Earth.

Using HTTrack to download links only under a certain subdomain (nothing external)

So, this is what I am trying to download - https://www.slader.com/textbook/9781337624183-calculus-9th-edition/
Looks fairly simple, I tried adding a few lines to "scan rules" to force it to download everything under it but for some reason, the entire process finishes under 10 seconds and it doesn't go further than just downloading the aforemention link itself.
For example, in addition to having https://www.slader.com/textbook/9781337624183-calculus-9th-edition/ itself, I would like to have all links originating from it, such as https://www.slader.com/textbook/9781337624183-calculus-9th-edition/311/ too.
Essentially, everything that starts with the first link above (including embedded pictures originating from other domains, but no external links.
As far as I know, adjusting a few settings and adding some rules to the "Scan Rules" section is supposed to do the trick, but I couldn't figure it out myself unfortunately.
In order to only copy links that are from that host and no other, to include the first link you submit you would need to setup scan rules.
On the menu page that you set the web address click the "Set options ..." button and then the Scan Rules tab. Next ensure your scan rules exclude all links, and then that they include the links from the source you want. And example of such a setup would be
+*.png +*.gif +*.jpg +*.jpeg +*.css +*.js -ad.doubleclick.net/* -mime:application/foobar
-*
+*[name].slader.com/*
This would essentially save all links originating from slader.com but would not store anything outside of that domain.
EDIT
If you only want links that begin with the link you typed in your scan rules would look similar to this:
+*.png +*.gif +*.jpg +*.jpeg +*.css +*.js -ad.doubleclick.net/* -mime:application/foobar
-*
+*[name].*[name]https://www.slader.com/textbook/9781337624183-calculus-9th-edition/*[name].*[name]/*
EDIT
You may not be able to get the other pages such as "Four Ways to Represent a Function" through HTTrack due to the way that specific sight has it's links structured. If you look at the source their links are posted like:
<tr data-url="/textbook/9781337624183-calculus-9th-edition/17/" class="exercise-group">
<td>1.1</td>
<td style="width: 360px;">Four Ways to Represent a Function</td>
<td style="width: 230px;">Exercises</td>
<td style="width: 74px;">p.17</td>
</tr>
As you can see they are using the data-url attribute to locate the next page utilizing a JS library to actually navigate the browser there. As this is not an anchor tag HTTrack doesn't know that it's suppose to follow it as it doesn't see it as a link.
Some alternatives would be to use something like Selenium or Scrapy to write a web-scraper with your own rules that would better understand it.

SharePoint 2013 "Download a copy" button/link for document library

I have a document library in SP2013 that is full of forms. My users get confused by the "Check Out Required" box that pops up when they open the file. I keep telling them they need to download a copy, but this seems to be an issue. So, I looked into adding a "Download a Copy" button or link to the library, and came up with this solution, which is put in a snippet on a Web Part Page (source: https://amalhashim.wordpress.com/2013/11/29/sharepoint-2013-document-library-download-a-copy-button/):
<script type="text/javascript">
function runAfterEverythingElse(){
var elementArray = document.getElementsByClassName("ms-vb-lastCell");
var idArray = document.getElementsByClassName("ms-listlink");
for(var i = 0; i < elementArray.length; i++)
{
elementArray[i].innerHTML = '<a unselectable="on" href="javascript:;" onclick="window.open(\''+ idArray[i]['href'] + '\')" class="ms-cui-ctl-large " aria-describedby="Ribbon.Documents.Copies.Download_ToolTip" mscui:controltype="Button" role="button" id="Ribbon.Documents.Copies.Download-Large"><span unselectable="on" class="ms-cui-ctl-largeIconContainer"><span unselectable="on" class=" ms-cui-img-32by32 ms-cui-img-cont-float"><img unselectable="on" alt="" src="/_layouts/15/1033/images/formatmap32x32.png?rev=31" style="top: -409px; left: -35px;"></span></span><span unselectable="on" class="ms-cui-ctl-largelabel">Download a<br>Copy</span></a>';
}
}
_spBodyOnLoadFunctionNames.push("runAfterEverythingElse");
This partially works, in that it puts a button next to each document that says "Download a copy," but the action is actually just open the file in Word (instead of in the browser). The check-out prompt is still there, so I know it's opening the file and not downloading a copy. So while I like the way it looks, but the functionality isn't right.
In the answers to another question here (How to trigger a file download when clicking an html button or javascript), I found some instructions, but I can't figure out how to use them. I tried creating a workflow that created a download link and put it in an html-formatted field, but can't get the formatting right.
I don't really care if the solution is library-based (a field on each document probably created through Nintex Workflow) or Web Part Page based (script/snippet). I'm not fluent with jquery, javascript, or other programming languages. I know HTML, and can fumble my way through with CSS, but I'm pretty much a straight copy-paste from the internet solution kind of girl. I am not a programmer, just the person who manages our SharePoint site alongside may other job functions. :)
Any advice on how to tweak the original code or how to do this better is greatly appreciated. We're using SP2013.
#Kelly I implemented this solution in sharepoint 2010 using Dataview webpart.
Dataview webparts loops through all the documents in doc library and below code allow user to download the file.
Test.docx - Download a copy
I hope it helps. :)

How to click on an anchor element using VBA in a webform

Can you give me here some code by which I can click on anchor label on a webpage. I want click on the "Configuration"label. These labels are used to navigate from one page to another page. Here is some part of the Web page view source.
<td class="tabtext-unsel"><nobr>Catalogs</nobr></td>
<td class="tabtext-sel"><nobr>Configuration</nobr></td>
After some discussion in comments i can suggest another answer:
Automation and Scripting Language
You may use this to navigate complicated pages, automate work in any application etc. It can copy almost any data and paste it to excel for example.
Maybe this will help you:
Youtube: MrExcel's Learn Excel #665 - Scraping Webpages
There is a technique called web scraping.
You may find many tutorials about web scraping, there are some tutorials for excel.

Using CreateObject("Excel.Application") - issues with unsigned control

We have a legacy ASP page that writes content to an excel file by generating client-side VB script based on data from the database. It uses set app = CreateObject("Excel.Application") to initialize Excel.
The problem is that this is an "unsigned activex control", and some clients are now saying they wont change their IE settings to make it work.
Apart from re-writing the page in ASP.NET using Aspose.Cells (which would take a long time for this page), I was wondering if anyone knows any other options that could help?
Thanks!
Although this thread refers to ASP.Net, a lot of it may be of interest to you:
Send query results to Excel from ASP.NET website
It mentions creating HTML output and modifying the headers to output to Excel. This may also be of interest http://support.microsoft.com/kb/199841
Here is a very simple example.
<%
Response.ContentType = "application/vnd.ms-excel"
%>
<TABLE>
<TR><TD>
<!-- Cell : A1 -->
2
</TD></TR>
<TR><TD>
<!-- Cell : A2 -->
3
</TD></TR>
<TR><TD>
<!-- Cell : A3 -->
=SUM(A1:A2)
</TD></TR>
</TABLE>
Thanks for the response. The problem is that the our spreadsheet generated has lots of additional functionality, e.g. setting up some "validation" for certain columns - the HTML solution would not be able to do this I think.
However - your answer forced me to take another look at the code, and it turns out simpler than I thought to do this using an "Excel Writer" like Aspose.Cells :)

Resources