My customer has a coded a function that takes 20 boolean values and comes up with an integer result.
They did it with Excel, as a complex formula.
In a new ROR web application, am I better off recoding the whole thing in Ruby, or somehow calling the Excel formula?
I could try to contact a server-side instance of Excel or headless OpenOffice and communicate with it using JACOB or the OpenOffice API?
You can use the spreadsheet gem to read from the Excel file. Try the following code, using a sample file in the same directory called ss.xls which has 1 in A1, 2 in B1, and =A1+B1 in C1.
#gem install spreadsheet
require 'spreadsheet'
book = Spreadsheet.open('ss.xls')
sheet = book.worksheet('Sheet1')
puts sheet.row(0)[2].value
The value call returns the last value for the cell that was calculated by Excel, with the above example it will output 3.0
Edit: Read more about the gem here: http://spreadsheet.rubyforge.org/GUIDE_txt.html
Edit 2: Of course, if you happen to be on Windows you will not need a gem; you just can use the win32ole library as described here: http://www.ruby-doc.org/docs/ProgrammingRuby/html/win32.html
No answers, so for now I will guess that re-implementing the formula in Ruby is less difficult than calling Excel/OpenOffice.
Feel free to provide a better answer!
Related
I am using PHPSpreadsheet and am reading in a spreadsheet with the following (working correctly) formula. I'm using Libre Office to generate my spreadsheet.
=SUMIFS($My_sheet.C:C,$My_sheet.B:B,">"&$'Home page'.$I$12,$My_sheet.B:B,"<"&$'Home page'.$I$13)
For some reason when I remove the offending rows my sheet reads/writes perfectly fine but with them I get corrupted files and it throws unreadable files.
I'm not setting the value - this is already in the spreadsheet I'm reading.
I hope this will help someone. I was looking for PhpOffice\PhpSpreadsheet\Calculation\Statistical\Conditional::SUMIFS() as your call.
For the example given simply wrap each , separated section in quotes and pass them to this function. So the answer would be:
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Conditional as StatCond;
StatCond::SUMIFS('$My_sheet.C:C','$My_sheet.B:B','">"&$\'Home page\'.$I$12','My_sheet.B:B','"<"&$\'Home page\'.$I$13')
My goal is to create automatic to-do's in several projects in Basecamp 3 on a weekly basis.
To do this, I am using the Schedule app in Zapier which triggers the creation of several rows on a google spreadsheet. These rows then trigger the creation of to-do's in specific projects in Basecamp 3. The input of this rows, should be: project's name (used for the search step), to-do text.
I am using the Formatter App in Zapier to try and achieve this. On a first Formatter action, I am splitting the text using commas of all of the names of our projects and returning all the segments. On a second Formatter, I am splitting the text of all the to-do's text and, again, returning all the segments.
Formatter 1 Input (Projects): AA,BB,CC,DD
Formatter 2 Input (To-Do's Text): buy it, use it, break it, fix it
Now, the goal I am trying to achieve is illustrated in the attached diagram. Also illustrated is what the zap (as it is) is achieving with the data. Data Stream Diagrams
We work often with Grasshopper, a Rhino 3D plug-in used for parametric modeling and data-drive design. In grasshopper this would be called a "cross-referenced" data-stream. Is this possible to achieve using Code in Zapier? If so, can I get a little help?
Thanks!
Zapier Zap GIF: https://drive.google.com/open?id=0B85_sQemABgmQVd6MENRd0NsNGc
I don't have permission to view your Google drive link, but I think I get the gist of what you're trying to do.
Rather than use Formatter, you're probably better off using Python as you'll have more control over what's getting returned. You can use Python's itertools.product to get every combination of your two lists.
# zapier runs in a vanilla python environment
# so you can import standard packages
import itertools
letters = ['AA', 'BB', 'CC', 'DD']
actions = ['buy it', 'use it', 'break it', 'fix it']
combos = list(itertools.product(letters, actions))
# [('AA', 'buy it'), ('AA', 'use it'), ... ('DD', 'fix it')]
From there, you'll want to format that list as your action step expects (probably via a list comprehension such as [{'code': c[0], 'action': c[1]} for c in combos] and return the list from the code step.
A hidden feature of Zapier is that if an array is returned from a code step, the zap will run the action for each array element. Be careful though, that means for each input to the zap, the output will be run 16x (which can quickly eat into your task limit).
Hopefully that sets you on the right track. Let me know if somethings was unclear!
I just started learning how to use mahout. I'm not a java programmer however, so I'm trying to stay away from having to use the java library.
I noticed there is a shell tool regexconverter. However, the documentation is sparse and non instructive. Exactly what does specifying a regex option do, and what does the transformer class and formatter class do? The mahout wiki is marvelously opaque. I'm assuming the regex option specifies what counts as a "unit" or so.
The example they list is of using the regexconverter to convert http log requests to sequence files I believe. I have a csv file with slightly altered http log requests that I'm hoping to convert to sequence files. Do I simply change the regex expression to take each entire row? I'm trying to run a Bayes classifier, similar to the 20 newsgroups example which seems to be done completely in the shell without need for java coding.
Incidentally, the arff.vector command seems to allow me to convert an arff file directly to vectors. I'm unfamiliar with arff, thought it seems to be something I can easily convert csv log files into. Should I use this method instead, and skip the sequence file step completely?
Thanks for the help.
I'm exporting data from a CxDBGrid to an Excel file.
I'm able to create the file and copy data in it, but I'm having real trouble with the column formatting. Since I'm pulling the data from a DB I'd like the spreadsheet to reflect the type: NUMBER, VARCHAR2,DATE and so on.
I visually created a macro, went to look for the VBA code, and replicated it in the Delphi project:
sheet.Columns[K+2].NumberFormat := '0,000'; //Number
sheet.Columns[K+2].NumberFormat := '#'; //Text
sheet.Columns[K+2].NumberFormat := 'm/d/yyyy'; //Date
Number formatting works ok most of the times, but the other two don't.
When I open the generated file, the text columns show up as type "Custom" and every cell displays "-64". If I go to edit a cell, the correct value is actually there.
Date is another issue: the DB's format is dd/mm/yyyy and if I feed it to Excel as-is, it gets all messed up. I tried setting the correct format, but then Excel doesn't recognize it.
Any clues?
I'm also setting column width. That works flawlessly.
The problem is that the assigned values are Unicode strings. Try this:
sheet.Columns[K+2].NumberFormat := AnsiChar('#');
sheet.Columns[K+2].NumberFormat := AnsiString('m/d/yyyy');
You haven't said "how you are doing things manually" which means people have to completely guess what you're doing. So here's my wild guess:
If I assume you're using the Express Spreadsheet component from Developer Express
I have estensive experience with this component. It does not support arbitrary numeric formats. It supports a "money" format (0.00) with exactly two decimal places. It does not support three or one, or any other number of decimal places.
If so, this is a known by-design issue in the Express spreadsheet.
If by manually you mean that "sheet" as you show above is an OLE object and you're communicating via OLE Automation to Excel itself, then you should be formatting CELLS either individually or as a range, and not column objects. I am not sure how column object formats would ever override the cell values, if they do at all. The formatting of cells is generally a cell by cell matter, and must be dealt with as such.
If you really want this to work properly you won't use Excel via OLE automation, you'll get a proper Excel XLS format capable writing library. I was quite sure that you could get proper results directly from the CX (DevEx) db grid, but I would ask on their forums, not here. With a regular DB Grid, I'd just use TJvDBGridExcelExport which comes in the Jedi JVCL, and which works with the regular VCL DB Grid.
could someone advise me on the most efficient way to gather data from one source, select a specific piece of data and insert it in a web page? Specifically, I wish to:
Call up this buoy data text file: http://www.ndbc.noaa.gov/data/realtime2/46237.txt
Find the water temperature and insert that value in my web page.
First big question: What scripting language should I use? (I'm assuming Fortran is not an option :-)
Second not so big question: This same data set is available in graphic and xml format. Would either of these data formats be more useful than the .txt file?
Thanks in advance.
Use Perl.
(Hey, you asked. Normally one programs in whatever language one would normally use.)
The XML format won't be much more useful than the text format.
This text file format is just about as simple as it could ever get. Just about any scripting or general purpose programming language will work. The critical part is to split each line on a regex "\s+". i.e. in Python it would be:
import re
theFileObject = open('/path/to/downloaded/file.txt')
for line in theFileObject.readlines():
columns = re.split(r'\s+', line)
# each column is columns[0] through columns[19]
So basically choose whatever programming language seems easiest to you. Any .NET language would be equally capable, as well as ruby, python, scheme, etc. I personally have a distaste for perl because I find it very difficult to read