Git Product home page Git Product logo

Comments (9)

gorn avatar gorn commented on August 10, 2024

@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.

whitehat101 avatar whitehat101 commented on August 10, 2024
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.

gorn avatar gorn commented on August 10, 2024

@whitehat101 Thanks. I will have a look at it.

from rspreadsheet.

gorn avatar gorn commented on August 10, 2024

it is failing the test under ruby 2.2.3 ...

from rspreadsheet.

gorn avatar gorn commented on August 10, 2024

@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.

whitehat101 avatar whitehat101 commented on August 10, 2024

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.

gorn avatar gorn commented on August 10, 2024

@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.

gorn avatar gorn commented on August 10, 2024

Feature implemented to sufficient extend now

from rspreadsheet.

gorn avatar gorn commented on August 10, 2024

@whitehat101 see also #23

from rspreadsheet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.