Comments (3)
There is currently no way of doing this. By design Xsv returns arrays of parsed primitives instead of proxy objects. The parsing for a 'd' type cell happens in
xsv/lib/xsv/sheet_rows_handler.rb
Lines 109 to 110 in e5d18c6
Perhaps you can reverse the effect of DateTime.parse
in your code?
from xsv.
I cannot reverse it because I am getting the Date object, not DateTime. Even though the underlying raw value has a time component saved, I am not getting datetime back because the cell is formatted as Date in xlsx. If I open xlsx file and change cell format to DateTime, then I get datetime value from xsv too. However those files are exported from a different system that I don't have control of so I need a way to either to override cell style/format or get access to raw value and convert it to datetime myself.
from xsv.
Ah, I forgot that exists. Indeed what you have is a number formatted as a date. The conversion is done by adding the number value to an epoch.
EPOCH = Date.new(1899, 12, 30).freeze
def parse_date(number)
EPOCH + number
end
This can be reversed:
irb(main):018:0> excel_value = 123.45
irb(main):019:0> parsed = parse_date(excel_value)
=> #<Date: 1900-05-02 ((2415142j,38880s,0n),+0s,2299161j)>
irb(main):020:0> (parsed-EPOCH).to_f
=> 123.45
I hope that helps! It would be interesting idea to add a middleware pipeline to Xsv to customize the parsing, but I have no time to build that. PR's are always welcome, though!
from xsv.
Related Issues (20)
- decimal records are not processed correctly HOT 2
- Parse empty file HOT 1
- issue parsing xlsx (formatting?) HOT 8
- test
- test
- Encoding::UndefinedConversionError when parsing non-ASCII character HOT 4
- NameError: uninitialized constant Xsv in Sidekiq Worker HOT 2
- hash mode as an argument or parse_headers! can return self HOT 1
- :symbolize_names option for hash mode HOT 5
- If PhoneticProperties data is included, NoMethodError (undefined method `+' for nil:NilClas) will be raised. HOT 3
- 1.0.2 NoMethodError: undefined method `scan' for nil:NilClass HOT 6
- Enhance parsing by headers HOT 3
- "Encountered unknown column type d" HOT 1
- Decimal values with % HOT 1
- NoMethodError: undefined method `[]' for nil:NilClass HOT 5
- Wrongly parsed hash HOT 5
- Generic HTML character entities not supported
- Breakage on Excel files without cell column names HOT 8
- Cell values are mapped to incorrect keys in Hash mode HOT 3
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 xsv.