Ruby: delete columns by name in MS Excel on Windows? - ruby

Is there a way to use Ruby to delete columns in an Excel spreadsheet by name (i.e. the value in the first row of the spreadsheet) on a Windows machine?
Background if you want it:
I am going to be receiving a large number of Excel spreadsheets on a regular basis. Some of these spreadsheets will contain columns that need to be deleted. I will know the names (first-row values) of the columns, but their positions in their respective spreadsheets will change from time to time, so I won't be able to automatically refer to the columns by letter. I would really like to be able to automate this process...

POI is the Apache project to create a library for reading MS Office files; it appears they have Ruby extensions. I have never used it before, but the code looks easy enough to understand. Good luck! Check it out here

You probably want to use the WIN32OLE library, built into the standard library on Windows. There's an example in PickAxe about using Microsoft Excel through the WIN32OLE library, and other examples here. You just need to learn how to use the Excel COM API to make the particular changes you're interested in.

Related

How to use VC++ to save data into an excel file?

I am new to VC++. I need to save data into an excel file. Please give me some direction. I have no clue where to start. Please help
Thanks
EPPlus is a library that allows to write and read excel files. I used it in c#, but I know it works in vb.net, so it should work for C++ as well since it's a dll.
http://epplus.codeplex.com/
If you simply want to write tabular data, one of the easiest solutions is to use ADO. You can perform an SQL INSERT query to write rows of data on an Excel worksheet: http://support.microsoft.com/kb/257819
OfficeWriter is another solution you may wish to check out. It's .NET so you'd link it in like EEPlus. Evals are free. It's pretty powerful, so it may be overkill depending on what exactly you are trying to generate. Also, disclaimer, I'm one of the engineers who built the latest version.

VB6 library for creating Excel spreadsheets

I am trying to get a legacy app working on terminal services with the minimum amount of changes to the existing code base.
What library for creating Excel spreadsheets using VB6 without having Excel installed could I use to solve this?
If you are using COM Interop to create Excel spreadsheets you must have Excel installed on the machine.
You could create comma delimited .csv files instead.
CSV is easy as suggested in the other answer. Sometimes folk use HTML too.
Create Excel (.XLS and .XLSX) file from C#
Or even ADO and OLEDB
http://support.microsoft.com/kb/195951/

MS Excel automation without macros in the generated reports. Any thoughts?

I know that the web is full of questions like this one, but I still haven't been able to apply the answers I can find to my situation.
I realize there is VBA, but I always disliked having the program/macro living inside the Excel file, with the resulting bloat, security warnings, etc. I'm thinking along the lines of a VBScript that works on a set of Excel files while leaving them macro-free. Now, I've been able to "paint the first column blue" for all files in a directory following this approach, but I need to do more complex operations (charts, pivot tables, etc.), which would be much harder (impossible?) with VBScript than with VBA.
For this specific example knowing how to remove all macros from all files after processing would be enough, but all suggestions are welcome. Any good references? Any advice on how to best approach external batch processing of Excel files will be appreciated.
Thanks!
PS: I eagerly tried Mark Hammond's great PyWin32 package, but the lack of documentation and interpreter feedback discouraged me.
You could put your macros in a separate excel file.
Almost anything you can do in VBA to automate excel you can do in VBScript (or any other script/language that supports COM).
Once you have created an instance of Excel.Application you can pretty much drop your VBA into a VBS and go from there.
If it's the Excel/VBA capability that you're looking to use then you could always start by creating all of the code that will interact with the Excel files you're wanting to work on within an Excel file - a kind of master file that is separated from the regular files, as suggested by Karsten W.
This gives you the freedom to write Excel/VBA.
Then you can call your master workbook (which can be configured to run your code when the book is opened, for example) from a VB script, batch file, Task Scheduler, etc.
If you want to get fancy, you can even use VBA in your master file to create/modify/delete custom macros/VBA modules in any of the target files that you're processing.
The info for just about all of the techniques I'm describing I got from the Excel VBA built-in reference docs, but it certainly helps to be familiar with the specific programming tasks that you're tackling. I'd advise that the best approach is to put together your tasks (eg, make column blue, update/sort data etc) one by one and then worry about the automation at the end.

Load MS Word files with AJAX

I want to dynamically load (AJAX) the text from some Microsoft Word files into a webpage. So I might have a link to essays I've written and upon mouseover have it load the first few sentences in a tooltip.
Only if you have a parser. I think the new format is a zip archive with XML schema. But the old one is just binary.
There are some parsers out there.
I know of wvWare but it seems it's outdated. (http://wvware.sourceforge.net/)
This is maybe something worth looking at: http://poi.apache.org/hwpf/index.html
And yeah, forgot to mention how to do this. :-)
First you need to make the javascript ask for the data through ajax. The serverside has to take care of the parsing and return the text to the javascript. This will be a pain in the ass. I haven't done this myself and have never tried the parsers I linked, so I'm not sure if they suit you. Images, stylesheets, etc.... not sure if that will be useable.
At least, good luck.
For security reasons, it is not possible to directly load a local file (such as a Word document) into the page using simply Javascript. The user will need to upload the file to the server, which you will want to parse on the server and then you can load whatever result you like into the page using Ajax.
It sounds like you mean to upload your files (e.g. essays) to your server to allow users to download them, and want to create a server-side page that will parse the files and print the first few lines (so it can be called by an AJAX method that displays a preview on hover).
To suggest a tool for this, we'll need to know whether these are "old" Word format (Office 2003 - extension is .doc) or "new" Word format (Office 2007 - extension is .docx).
It will also be good to know what you're using to create your pages server-side, since different document-reading tools support different programming languages. If you're using Java to read .doc files, you can use the tool we use at my place of work, which is POI (http://poi.apache.org/). If you're using something else, try searching google for {read in }, e.g. {read .docx in ruby}.
If all of this is Greek to you and you have no prior experience with developing custom server-side web code, this is probably going to be unnecessarily painful and you should consider an alternative (like manually creating a 3-line text "preview" page for each regular page, and then just showing that).

Can I generate Excel files with native Excel charts on Linux?

Is there a way to generate Excel spreadsheets with Perl on Linux so that I can open the spreadsheet on Windows and it creates native Excel graphics? I know that there are libs to draw graphics but all libs I know simply insert a picture to the Excel which looks weird when I open the spreadsheet on Windows. So I wondering is there a way to do it better? Possibly I could embed a VB script or something so that it creates a graphics automatically when I open the spreadsheet on Windows? The original spreadsheet must be generated on Linux so there are no ways to use OLE or some other Windows-only technology.
Thanks guys! Spreadsheet::WriteExcel seems to be a good solution. Did not understand at the first glance if it allows to change dimensions of data or it is hardcoded in a template file (10 points for example, no more, no less). Does anyone know?
If anyone knows another way of doing my task, please post it here. I'm interested in comparing of different solutions and select the best.
Yes, Spreadsheet::WriteExcel has a embed_chart($row, $col, $filename, $x, $y, $scale_x, $scale_y) function which lets you do this.
Spreadsheet::WriteExcel allows you to insert charts from existing files (with some caveats).
See, the following sub-document on Spreadsheet::WriteExcel Charts and the examples files in the distro, such as this one.
P.S. I am the author of that module.
Try Spreadsheet::WriteExcel.

Resources