Select, Copy from IE and paste to Excel - html

So the basic question is, how can I make table nicely copy pastable from IE to Excel or OpenOffice calc.
The page is located here: http://tuudik.lohv.eu/Asjad/EURXML/
The table is created dynamically by PHP code. There's a button with tekst "Vali tabel!" which means, it selects the table. Then I want to copy it, for example using CTRL+C and paste it into a spreadsheet.
What are the best options? Should I create a hidden div what then has the same Data like in the table but formatted other way?
Also, anyone knows how to make the "Vali kõik!" button work so, that it would automatically copy the contents to the clipboard?

Why not modify your PHP script to write the page content directly to Excel, writing the content to excel cells rather than HTML where you're writing to the
<td> elements, then set the headers to download it... so passing an additional 'format' parameter to your script could determine the output format as HTML of XLS. The PHPExcel library offers the capability of generating XLS files in pure PHP. A link on your HTML page could then offer the option to recreate the output directly as an XLS file for download, rather than copy-and-paste.

In my experiences copying from html pages is best done through a text editor that doesn't have formatting. This way the content is usually delimited in some kind (tab usually) that makes pasting to a spreadsheet much easier.
Copy table from browser
Paste in notepad, select, copy again
Paste in Spreadsheet application
Might not answer your question directly but if you somehow can make the data copyable as plain text with tab delimiter (as in a hidden div or something) - you would probably have greater success in pasting it into spreadsheets that supports all kinds of formatting.

Using a slightly different approach, try the Get External Data feature in excel
( i tested on Using Excel 2010, but 2007 is similar, and it is available in 2003 in a slightly different guise )
From menu Data/Get External Data/From Web
opens a form:
paste address;(eg http://bit.ly/Kurss) and click Go
web page is displayed
scroll down to the table you want
select it with the little yellow arrow thingy
Click Import
Voila, data is in excel, as unformatted data from a background query!
Then whenever you waht to update the data, just click Refresh

I to needed a way to copy html table information and paste into excel. I used a combination of techniques. First I added this code so I could automatically copy data into the paste buffer of the clients pc.
How do I copy to the clipboard in JavaScript?
// Copies a string to the clipboard. Must be called from within an
// event handler such as click. May return false if it failed, but
// this is not always possible. Browser support for Chrome 43+,
// Firefox 42+, Safari 10+, Edge and IE 10+.
// IE: The clipboard feature may be disabled by an administrator. By
// default a prompt is shown the first time the clipboard is
// used (per session).
function copyToClipboard(text) {
if (window.clipboardData && window.clipboardData.setData) {
// IE specific code path to prevent textarea being shown while dialog is visible.
return clipboardData.setData("Text", text);
} else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
var textarea = document.createElement("textarea");
textarea.textContent = text;
textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in MS Edge.
document.body.appendChild(textarea);
textarea.select();
try {
return document.execCommand("copy"); // Security exception may be thrown by some browsers.
} catch (ex) {
console.warn("Copy to clipboard failed.", ex);
return false;
} finally {
document.body.removeChild(textarea);
}
}
}
I then created a copy string. Separate the cell values by a tab \t and separate the rows by a new line \n. see the example below.
I create the copy data string using PHP.
//-- Create data for a single table row
//-- We needed to escape single quotes for HTML and javascript
$copy_data = str_replace("'","\'",$col1."\t".$col2."\t".$col3);
//-- Create data for a multi rows
//-- Separate multiple rows by \n but needs to be escaped so use \\n
$copy_data = str_replace("'","\'",$col1."\t".$col2."\t".$col3."\\n".$col1."\t".$col2."\t".$col3."\\n".$col1."\t".$col2."\t".$col3);
Then I place it in a copy button on the web page.
Copy
Then you click on the "Copy" link to get the data into your copy buffer. Next go to Excel and click in the cell where you want to paste the data, then do a paste.

Related

How can I set the page size for a PDF created (from HTML) and emailed using AppMaker?

I have a function in my AppMaker app that works like a charm -- when you click on a button, it takes the data from the current record, applies some logic to it, and mashes it up and styles it as HTML. I want to deliver the results to the user in two ways:
Print -- the function has a return that sends the HTML back to the browser, which opens up a print dialog as expected.
PDF by Email -- the function also generates a PDF which is attached to an email sent to the user.
I heard feedback from users that the PDF version cuts off the bottom two lines, so I'm trying to find out why.
To send the PDF as an email attachment, I use Utilities.newBlob() to first blobify my HTML. Then I get the blob as a PDF, and then I send the PDF as an email attachment. The code looks like this:
var pdfContent = Utilities.newBlob(html, 'text/html', 'PE-' + name + '.html')
var pdf = pdfContent.getAs("application/pdf");
GmailApp.sendEmail(to, subject, body, {attachments: pdf});
The email is delivered correctly with a PDF attached to it, and when you open it up, it looks pretty much like the HTML that gets sent to the print dialog. When you go to print it, though, the last lines clearly get cut off. My advice to users (until I could dig into the problem) was to use the "Fit to Page" function in the print dialog. Looking at it more closely, though, I had an inkling that it might be a page size issue -- there's something off about the proportions when you view the PDF. Sure enough, upon changing the paper size from letter to A4 in the print dialog, the page lays out perfectly.
So now I can't figure out where the default to A4 is happening.
I tried setting the #page attribute for size in the <style> tag, with no effect -- it doesn't seem to survive the transition from HTML to blob to PDF:
html += '<style>#page {size: 215.9mm 279.4mm; margin: 15mm;}</style> etc...';
For size I've used millimeters (as above) and px as units, and I've tried just using the word 'letter'. No version of the above works.
Is there some other place where I can specify page size to make this stop happening?

Load values of a file at an html form

Is there any way to load the values of .txt file or .doc file and insert them at an html form as possible values? For example i have rooms 1-10 written at a txt file, and a form that i will need to scroll and check anyone of that rooms. Thanks
In the past I did the following: one iFrame loads the txt file, with the visibility: hidden;position: absolute style. Its onLoad event triggers a Javascript function which can parse it. I usually use this reading function:
iframeObj = document.getElementById('put here the iFrame ID')
if (iframeObj != null)
{
if (iframeObj.contentDocument)
{
txtfilecontent=iframeObj.contentDocument.getElementsByTagName("BODY")[0].innerHTML;
}
else if (iframeObj.contentWindow)
{
txtfilecontent=iframeObj.contentWindow.document.body.innerHTML;
}
// Here you can use the txtfilecontent, which is a string
}
Usually I trigger a reload of the txt file in the end, but if you have to fill a form it is not recommended.
If you want to do that before loading the page, however, you should use a server side code, such as PHP and its file_get_contents function. The advantage of this approach is that you won't need to expose the txt file to the user, but it can stay hidden on the server.

How to show a preview of a file on a panel in a UiApp using GAS

I want to display a preview of a(ny) file on a panel in a UiApp using GAS.
I'm using DriveApp, not DocsList.
Using file.getThumbnail() or file.getAs(mimeType) I can get a Blob of any file.
Documentation at https://developers.google.com/apps-script/reference/drive/file#getThumbnail%28%29 states that (at least) I can get those blobs being converted to 'application/pdf'.
I don't know how to display those blobs (or pdf-files as such) on a panel.
Can anybody tell me what I should do?
You cant display them inside the panel because you would need to iframe it, which isnt possible even with htmlServices.
Use an anchor to open the link on another page. You can link to the original file.
You can convert a spreadsheet with a pdf but i don"t know with any File.
I use this code
var pdf = DocsList.getFileById(newSpreadsheet.getId()).getAs('application/pdf').getBytes();
var attach = {fileName:'Weekly Status.pdf',content:pdf, mimeType:'application/pdf'};
You cna test It with this source if he can help you .
https://gist.github.com/ixhd/3660885

How to create links to sections in pdf

Can we create a hyperlink or an embed tag that will display a specified page/section of a PDF document?
let me know if anybody has any idea
ex:
Open PDF using subsection
I know appending #page=X works, but I've now had some luck appending #subsection.X.Y. For example: http://tug.ctan.org/macros/latex/contrib/beamer/doc/beameruserguide.pdf#subsection.14.1
Just to go to an existing PDF file page you can use
#page=pageNumber
PDF parameter.
Yes it seems to be possible, please see this link http://www.pdfobject.com/examples/index.php and http://www.pdfobject.com/ for more information. This is from the site "PDFObject is an easy-to-use method for dynamically embedding PDF files into HTML documents. It uses JavaScript to generate and inject a standards-friendly "
<script type="text/javascript">
window.onload = function (){
var success = new PDFObject({ url: "http://www.adobe.com/content/dam/Adobe
/en/devnet/acrobat/pdfs/pdf_open_parameters_v9.pdf#page=6&zoom=150,0,216"
}).embed("pdf");
};
</script>
As you can see you can change the URL link to
thefile.pdf#page=YOURDESIREDPAGE
Linking to a destination within PDF in a webpage as found on this page,
Citation start:
"
Linking to a destination is essentially the same principle but involves a few more
steps
and setting up. First up, you'll need to create the destination.
Creating a destination in a PDF using Adobe Acrobat:
Manually navigate through the PDF for the desired location, and magnification.
Move your curser to the right of the PDF, in the navigation pane.
Right click and select destination. This will open the Destinations pane.
Right click, select New Destination enter an appropriate name and select the area that
you want the destination to link to.
NOTE: Make sure that the name does not have any spaces as it makes it easier to link to
afterwards.
You are now ready to link to the destination using a similar syntax as linking to a
specific page, instead of #page write #nameddest.
Append "#nameddest=" and the name of your chosen destination. So, if your PDF has a
named destination, "TOC", that points to a table of contents, then your link code will
look like this:
Link Text
"

How to get links in Excel to open in single browser tab

I have an Excel spreadsheet with html links in one column. The links are being generated by a perl script via Win32::OLE like so (inside a loop with index $i):
my $range = $Sheet->Range("B".$row);
my $link = "http://foobar.com/show.pl?id=$i";
$Sheet->Hyperlinks->Add({Anchor=>$range,Address=>$link,TextToDisplay=>"Link to $i"});
Currently, every time I click one of these links, it opens in a new browser tab. Since there are a lot of these links I wind up with 20 tabs after working with the sheet for a while. This is a pain in the behind because I periodically have to go through and close them.
Is there some way to get these links to open in the same browser tab? I don't know if it's possible to specify the HTML equivalent of an anchor target with a constant name using the Hyperlinks->Add method, or if this would even do the job.
Depends on which browser you are using:
For Firefox, see this link Force Firefox To Open Links In Same Tab
Requires setting option in about:config browser.link.open_newwindow = 1
For IE, Tools/options/General/Tabs/Setings
Open links from other programs in: The current Tab or Window
Try using Spreadsheet::WriteExcel
#!/usr/bin/perl -w
use strict;
use Spreadsheet::WriteExcel;
# Create a new workbook called simple.xls and add a worksheet
my $workbook = Spreadsheet::WriteExcel->new('Example.xls');
my $worksheet = $workbook->add_worksheet();
# The general syntax is write($row, $column, $token). Note that row and
# column are zero indexed
# Write a hyperlink
$worksheet->write(10, 0, 'http://perldoc.perl.org/');
$worksheet->write(11, 0, 'http://stackoverflow.com/');
__END__
the hyperlinks are opened in same browser tabs(works fine in IE,Firefox,Chrome)
So I have found the docs for the Excel object model, and there are no properties of a hyperlink that would indicate this is possible. Thanks for the come-backs tho.