Copy Spreadsheet Ready CSV to Clipboard - javascript

I would like to display some comma separate values to a user in JavaScript (but really, language is not the point here) and allow them to paste that right into their spreadsheet program, much like SQL Server Management Studio does.
For example, in SQL Management Studio (and other programs), if I select the columns here, I can paste those right into Excel, no formatting or importing needed.
If I just output CSV as it is:
It puts everything in one row:
What do I need to do to my output to make it so when I copy it, I can just easily paste it into a spreadsheet program?

Related

Script to copy range/cells value from Google Spreadsheet - paste in Excel

I'm looking for a script that can simply help me COPY a specific range in Google Spreadsheet so I can just paste it in an Excel file where this data will be processed.
The "dream" solution would be to connect and paste automatically the range from the G-Spreadsheet into the Excel file, but if there is a possibility to run a script that will "memorize" all the wanted range so I can just click "paste" in Excel - it would be a life saver!
Many thanks!
Appscript has a method getRange where you can use to copy data from one Google spreadsheet to another, but Google spreadsheet to Excel operations is not yet supported
something to that effect. What do you think?
For the meantime, you might reconsidering downloading your spreadsheet as csv so that you can open your google spreadsheet contents in Excel.
I would process data in Google Sheets. It's better. But if you insist...
First, write GAS code on source Google Sheet. The script executes these steps:
fill all unwanted area xxx or something.
save the sheet to csv file.
now, undo step 1.
Second, write VBA code on target Excel file. The script executes these steps:
open the csv file created by above GAS code.
read all values. You may skip xxx.
pastes those values into specific target area.
Then you just click one time in Google Sheets, and click another time in Excel and tadah! You got it.
Again, I would process data in Google Sheets.

Changing a cell value in a xlsl sheet while keeping the format nodejs

Title is what I'm trying to achieve. Basically I want to edit a existing excel sheet that is formatted with fonts/styles etc and keep those fonts/styles intact while changing a particular cells value.
I've tried using the xlsx npm module, I've been able to change the cell to the value I want and save the file, but when doing so all the style is lost.
I was wondering if you guys could give me any directions on what to try now.
I only want to use nodejs for this project.
Thanks guys.
In documentation it says: The raw data is the only thing guaranteed to be saved. Formulae, formatting, and other niceties may not be serialized (pending CSF standardization) under writing options section.

Read and Write DOCX file

I have 2 docx files that I am working with. One docx file contains text information of a product (start serial number, length, width, and height). The other docx file contains a sticker label with an image and all of the text information from the first file.
This is what I do currently:
I open the first docx file and copy all of the text information (serial, length, width, and height)
Then I paste each info into the second docx file that contains the formatted label.
If I need to make more than one label, I copy the label and increment the serial number by 1.
This takes a lot of time to make several labels for different products. My goal is to come up with an easier way to take data from one docx and inject it into the other. Also, generating more labels when needed.
My first thought was to extract the docx file to get it's xml contents. Then read the data using javascript, c++, or any other language. Then Ask user to input number of labels to generate, manipulate the xml, and repack it as a docx file.
Then I thought about trying to use the windows office "mail merge" feature, but I have never done this before.
I would like to know if anyone has any suggestions for an easy solution to import data from one docx file and generating labels into another.
I am open for any suggestion.
Also, I am not a professional programmer. I am an undergraduate computer engineering student with some experience in c, c++, java, javascript, python, MIPS assembly, and php.
The only open-source (and probably easier to come by) solution I know know is:
http://poi.apache.org/
http://poi.apache.org/document/quick-guide-xwpf.html
This is a good bet when it comes to speed and it is free software.
But if you open a file, alter it and save it again - the result can be flaky: The formatting can be slightly off. At least in my tests with the pptx counterpart.
I reckon when you have user interaction (web page?) in order to create the document, you can build a small HTTP Api around the library.
There is also: http://www.docx4java.org/trac/docx4j - which I have not tested yet.
You can also go the C#/Redmond way: How do I create the .docx document with Microsoft.Office.Interop.Word?
The Interop (2nd Example in the first answer of the question above) way gives the best result when it comes to the accuracy of the formatting. Basically when you open a file with Interop - it will look the same when you alter and save it. But you cannot use this when interacting with a user - because it starts a separate MS Office process - and I would not count on this from my own user experience. But if you want to generate these files as a batch in a single user session - it will deliver a good result.
I cannot comment on the "OpenXML SDK" library described in the above SO question.
Wath about the Open XML https://www.youtube.com/watch?v=rMnEl6JZ7I8 and website developer http://openxmldeveloper.org/ .
On the site you found sdk for:
Open XML SDK for JavaScript: http://openxmldeveloper.org/wiki/w/wiki/open-xml-sdk-for-javascript.aspx. Demo: http://openxmldeveloper.org/blog/b/openxmldeveloper/p/openxmlsdkjs_demo.aspx
Open XML and Java http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2006/11/21/openxmlandjava.aspx
.Net Resources http://openxmldeveloper.org/resources/dotnet/m/cc/default.aspx

Excel Macros with Javascript

I wish to manipulate excel spreadsheets using macros in Javascript rather than the default VBA. I can execute javascript code using the following VBA code
'javascript to execute
Dim b As String
b = "function meaningOfLife(a,b) {return 42;}"
'VBA tool to run it
Dim o As New ScriptControl
o.Language = "JScript"
o.AddCode b
MsgBox o.Run("meaningOfLife", 0, 1)
this enables me to execute arbitrary javascript, however I do not have access to the excel spreadsheet from within the javascript environment. Is there any way I can set and get worksheet values in the active worksheet from within javascript?
For people using Excel 2016 or later version, there is an Excel add-in called Funfun in the add-in store that actually allows you to write and run JavaScript code directly in Excel. And of course, your JavaScript code also has access to the data stored in the spreadsheet. Here is a screenshot of how it looks like in Excel
2016.
Well in the middle of the interface you have a section in which you could write JavaScript, CSS and HTML code. It is pretty much like a playground built into the Excel. But the Funfun also has an online editor in which you could test with your code. You could see it in the pic below. I also posted the link of the example in the first picture so you could play with.
https://www.funfun.io/1/#/edit/5a4e0d461010eb73fe125c4e
What is special about the Funfun online editor is that it contains a 'spreadsheet' just like Excel. Though you can't actually do any formatting in here, you could copy your data into the cells and test your code directly.
To use the data stored in the spreadsheet, all you need to do is to write some configuration in the short.io file of Funfun to tell JavaScript which area in the spreadsheet that contains your data. For example, in the example that I posted, all you need to write is
{
"data": "=A2:B9"
}
And in the JavaScript code, an object called $internal is used to read the data. So in order to read the data that stored in A2:B9, you need to write
var data = $internal.data;
And its done. You could go to the documentation of Funfun if you want to know more.
If you are satisfied with the result you achieved in the online editor, you could easily load the result into you Excel using the URL above. Of couse first you need to insert the Funfun add-in from Insert - My add-ins. Here are some screenshots showing how you could do this.
Disclosure: I'm a developer of Funfun
It depends what sort of "Excel programming" you want to do.
If you want to manipulate Excel files, you can do so via COM automation, or even ODBC to some degree, using JavaScript running under the Windows scripting environment.
But if you want to have your code running within an active Excel session doing things the visitor will see, you have fewer options.
See this question I posted a few years back when I had some JavaScript I wanted to run within Excel and didn't have the budget to convert to VBA:
How can I use JavaScript within an Excel macro?

what language do i use to write a webpage in to automatically update from a database of sorts?

I have what I consider a bit of a tricky question. I am currently working on quite a large spread sheet (266 rows aith 70 coloumns and its only going to get bigger) that is a database of sorts and I want to remove it from Excel and put it on to an intranet page. I am currently writing it in a combination of HTML and Javascript for functionality, but it is becoming very hard to ensure that the data is in the right place. I am wondering if there is a possible way of being able to save the Excel spreadsheet into a certain format (like CSV or XML) and then write a program (for on a HTML page) that would display all of the infomation in a table automatically? is this even possible?
Unfortunatly i do not have access to a server to be able help with this, it all needs to be able to be coded in the page itself.
Thankyou for all your input Guys and Gals
Based on your comment, a normalized database for this type of thing would look like this:
table `workers`
- id
- name
- ...
table `trainings`
- id
- title
- description
- ...
table `workers_in_training`
- worker_id
- training_id
This allows you to create a logical matrix as well without the need to change the schema (keep adding columns) for each new training/worker. Of course, this realistically requires a database server of some sort and knowledge in a server side programming language (PHP, Python, Ruby, C#, anything). If you don't have that, an Access database/app may be an acceptable compromise. Doing it all in Javascript is certainly interesting, but is an idea you should abandon as early as possible.
Given your constraints, I would save the Excel spreadsheet as a CSV and put it in the same location as your HTML file, then use AJAX to fetch the contents of the CSV and dynamically generate a HTML table based on the contents.
Look here for how to fetch a URL's contents using AJAX (jQuery library): http://api.jquery.com/jQuery.get/
After fetching the URL content, you will have the CSV as a big string in a JavaScript variable. I'll let you have the fun of figuring out how to parse it :-)
Once you know how to parse your CSV string to recognise rows and columns, look here for how to generate HTML table dynamically using jQuery library: Building an HTML table on the fly using jQuery

Categories