Comments (9)
@whitehat101 What exactly you are trying to achieve? Can you send me the code (or pseudocode) you are expecting to work, so I have nave a look at it?
from rspreadsheet.
require 'rspreadsheet'
book = Rspreadsheet.open './time.ods'
sheet = book.worksheets(1)
# cell = sheet.A1 # exception
cell = sheet.cells('A1') # works
# cell.to_s # exception
Github issues doesn't support ODS uploads, so this is an ODS with it's extension changed to zip (not an ODS inside a zip)
time.zip
I'm looking to set time values like what's in A1. I don't really need to_s
to work, but the IRB REPL was calling it automatically. I bet I can work with cell = sheet.cells('A1')
to set this.
from rspreadsheet.
@whitehat101 Thanks. I will have a look at it.
from rspreadsheet.
it is failing the test under ruby 2.2.3 ...
from rspreadsheet.
@whitehat101 ok, it needed one more thing - to clean up the value when changing the cell from time to another type of contant. It works now. There is another issue though and it is the text part of nodes. You set it up with hardcoded format, but I am sure people will want to influence how time looks like in their spreadsheet. Ideally it would be able to accept all usual Calc formatters as well as the Ruby ones. I will investigate this and if you have any ideas, let me know.
from rspreadsheet.
That's completely reasonable about the text value format. I just followed my sample's format. However, all the other formats in value=
are also using hardcoded formats in their text:p
nodes, so it seems like user formatters aren't quite a thing yet. (Unless this is being rewritten later?)
While looking at this I found: http://books.evc-cit.info/oobook/ch05.html#table-value-table
If it contains a simple date, it is stored in the form yyyy-mm-dd; if there is both a day and a time, it is stored in the form yyyy-mm-ddThh:mm:ss.
The value is stored in the form PThhHmmMss,ffffS (where ffff is the fractional part of a second).
I started considering:
DateFormats = ['%Y-%m-%dT%H:%M:%S', '%Y-%m-%d']
TimeFormats = ['PT%HH%MM%SS,%LS', 'PT%HH%MM%SS']
And then having a method try each format, rescue and try the next format as needed. Right now, if you have a long format field it'll parse without error, but the extra data will be ignored.
But encoding/decoding long time turns out to need slightly different format strings:
# %4N works for formatting, but not parsing
# ArgumentError: invalid strptime format - `PT%HH%MM%SS,%4NS'
# parsing with %L preserves the 4 fractional digits
t=Time.strptime Time.now.strftime('PT%HH%MM%SS,%4NS'), 'PT%HH%MM%SS,%LS'
t.nsec
In addition to the quirks with time, the long date format is actually better represented by Ruby's DateTime anyways. So, arrays of format strings aren't quite the solution.
My sheet doesn't make use of these features, but since I looked around might as well make notes.
from rspreadsheet.
@whitehat101 gorn:
I am completely fine with evolutionary approach to rspreadsheet so the change introduced right now is nearly exactly what I would call the "minimum change" to make it work.
No the format is not supported for other types either, because I did not need it yet. I think that first time I will need it for currency and/or date. At this point I will implement it on some systematical way.
from rspreadsheet.
Feature implemented to sufficient extend now
from rspreadsheet.
@whitehat101 see also #23
from rspreadsheet.
Related Issues (20)
- FODS support HOT 7
- Setting background color get more cells colorized HOT 13
- Tests failing for ruby >= 2.4.6 HOT 1
- Cells table:covered-table-cell ignored.
- Repeated header rows (contained in table:table-header-rows) are ignored.
- method mispelled: Rspreadsheet::Row#lenght should be #length HOT 1
- Existing formulas do not calculate fields set by rspreadsheet HOT 9
- libxml gem not installed automatically on windows HOT 9
- Header rows are not respected HOT 1
- Rubyzip 1.3.0 and 2.0.0
- rewriting cell addresses in formulas when inserting rows / cells HOT 1
- Size does not ignore formatted cells without content HOT 9
- Randomly crash HOT 1
- Bundler doesn't detect libxml-ruby as a transitive dependency on macOS
- Can we open password protected file HOT 1
- Uncaught exception: cannot load such file -- libxml_ruby even if it's installed. HOT 2
- Problem writing cell with a drop-down list
- Unclear how to set cell number format for date etc.
- Charts in source .ods file cause an error when trying to save. HOT 1
- Iterate worksheets
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rspreadsheet.