I'm using the IEEEtran-de package and need to add the term
Zugriff am: DD. MM YYYY
(URL access date) behind the URL. I tried to look up the IEEEtran-de.bst code and search for the relevant lines, but I'm pretty overstrained ...
Is someone familiar with this package and can help me out?
I'm on Rails 5 (Ruby 2.4). I want to read an .xls doc and I would like to get the data into CSV format, just as it appears in the Excel file. Someone recommended I use Roo, and so I have
book = Roo::Spreadsheet.open(file_location)
sheet = book.sheet(0)
text = sheet.to_csv
arr_of_arrs = CSV.parse(text)
However what is getting returned is not the same as what I see in the spreadsheet. For isntance, a cell in the spreadsheet has
16:45.81
and when I get the CSV data from above, what is returned is
"0.011641319444444444"
How do I parse the Excel doc and get exactly what I see? I don't care if I use Roo to parse or not, just as long as I can get CSV data that is a representation of what I see rather than some weird internal representation. For reference the file type I was parsing givies this when I run "file name_of_file.xls" ...
Composite Document File V2 Document, Little Endian, Os: Windows, Version 5.1, Code page: 1252, Author: Dwight Schroot, Last Saved By: Dwight Schroot, Name of Creating Application: Microsoft Excel, Create Time/Date: Tue Sep 21 17:05:21 2010, Last Saved Time/Date: Wed Oct 13 16:52:14 2010, Security: 0
You need to save the custom formula in a text format on the .xls side. If your opening the .xls file from the internet this won't work but this will fix your problem if you can manipulate the file. You can do this using the function =TEXT(A2, "mm:ss.0") A2 is just the cell I'm using as an example.
book = ::Roo::Spreadsheet.open(file_location)
puts book.cell('B', 2)
=> '16.45.8'
If manipulating the file is not an option you could just pass a custom converter to CSV.new() and convert the decimal time back to the correct format you need.
require 'roo-xls'
require 'csv'
CSV::Converters[:time_parser] = lambda do |field, info|
case info[:header].strip
when "time" then begin
# 0.011641319444444444 * 24 hours * 3600 seconds = 1005.81
parse_time = field.to_f * 24 * 3600
# 1005.81.divmod(60) = [16, 45.809999999999999945]
mm, ss = parse_time.divmod(60)
# returns "16:45.81"
time = "#{mm}:#{ss.round(2)}"
time
rescue
field
end
else
field
end
end
book = ::Roo::Spreadsheet.open(file_location)
sheet = book.sheet(0)
csv = CSV.new(sheet.to_csv, headers: true, converters: [:time_parser]).map {|row| row.to_hash}
puts csv
=> {"time "=>"16:45.81"}
{"time "=>"12:46.0"}
Under the hood roo-xls gem uses the spreadsheet gem to parse the xls file. There was a similar issue to yours logged here, but it doesn't appear that there was any real resolution. Internally xls stores 16:45.81 as a Number and associates some formatting with it. I believe the issue has something to do with the spreadsheet gem not correctly handling the cell format.
I did try messing around with adding a format mm:ss.0 by following this guide but I couldn't get it to work, maybe you'll have more luck.
You can use converters option. It seems looking like this:
arr_of_arrs = CSV.parse(text, {converters: :date_time})
http://ruby-doc.org/stdlib-2.0.0/libdoc/csv/rdoc/CSV.html
Your problem seems to be with the way you're parsing (reading) the input file.
roo parses only Excel 2007-2013 (.xlsx) files. From you question, you want to parse .xls, which is a different format.
Like the documentation says, use the roo-xls gem instead.
App uses SOAP4r for consuming API/SOAP
But SOAP::SOAPTimeFormat is returning
2015-11-15T16:59:521468.7999999999999545-04:00
chkout.add('purchasedDt ', SOAP::SOAPDateTime.new(basket.purchase_Date))
Using strftime('%Y-%m-%dT%H:%M:%S') is giving the following
chkout.add('purchasedDt ', SOAP::SOAPDateTime.new(basket.purchase_Date.strftime('%Y-%m-%dT%H:%M:%S')))
2015-11-15T16:59:52Z
What App needs is
2015-11-15 16:59:52 -0400
Please advise ...need the format in
yyyy-mm-ddThh:mm:ss-/+gmt
-Fransis
A simple change in your strftime and you can find out more in the doc for Time#strftime
basket.purchase_Date.now.strftime('%Y-%m-%d %H:%M %z')
=> "2016-04-26 22:48 -0400"
Seems like your applicaton accepts the iso8601 format. You can use Time#xmlschema as a shortcut to generate iso8601 compatible strings:
basket.purchase_Date.xmlschema
#=> "2015-11-15T16:59:52-04:00"
Just change this line in your example:
chkout.add('purchasedDt ', SOAP::SOAPDateTime.new(basket.purchase_Date.xmlschema))
I'm trying to use the iCalendar gem to import some iCal files on a rails 4 site.
Sometimes the file is of type 'text/calendar;charset=utf-8' and sometimes its 'text/calendar; charset=UTF-8;'
I am retrieving it like this:
uri = URI.parse(url)
calendar = Net::HTTP.get_response(uri)
new_calendar = Icalendar.parse(calendar.body)
When its text/calendar;charset=utf-8 it works fine. but when its text/calendar; charset=UTF-8 encoded I get UTF codes in the string
SUMMARY:Tech Job Fair – City(ST) – Jul 1, 2015
ends up being
["Tech Job Fair \xE2\x80\x93 City(ST) \xE2\x80\x93 Jul 1", " 2015"]
Which is then saved to the database and that is undesirable.
Is the charset/content-type revealing the problem here or could it actually just be encoded wrong from the source?
How do I change my retrieval commands to strip those codes out effectively or tell it its a UTF string so it doesn't include them in the first place?
Update: it looks like some are text/calendar;charset=utf-8 and some are text/calendar;charset=UTF-8 and some are text/calendar; charset=UTF-8. Note the last one has a space between the two segments. Could this be causing an issue?
Update2: Opening up my three example iCal files in Notepad++ shows them encoded as "UTF-8 without BOM" in the menu.
I have an email extracted from an IMAP account. I have encoded it like this:
body = imap.uid_fetch(uid, "BODY[TEXT]")[0].attr["BODY[TEXT]"].force_encoding('UTF-8')
So now it looks like this:
puts body.inspect => "\n--Apple-Mail-028364EC-0K8B-4FD7-87E8-97C28C324717\nContent-Type: text/plain; charset=\"utf-8\"\nContent-Transfer-Encoding: quoted-printable\n\nHej=20\n\nI m=C3=A5 meget undskylde men jeg vil ikke k=C3=B8be produktet alligevel hvord=\nan g=C3=B8r vi det...=20\n\nHans Nielsen. =20\nR=C3=B8rgade 65=20\n1234 G=C3=B8rlev\n\n"
I want to present the email in my Rails app, so the user of the app can review the email. But how do I clean up the body?
I want to remove this part:
--Apple-Mail-028364EC-0K8B-4FD7-87E8-97C28C324717
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
And clean up this part:
Hej=20
I m=C3=A5 meget undskylde men jeg vil ikke k=C3=B8be produktet alligevel hvord=
an g=C3=B8r vi det...=20
Hans Nielsen. =20
R=C3=B8rgade 65=20
1234 G=C3=B8rlev
This means replacing the weird characters with the originally intended characters. Fyi, these are:
=C3=A5 is å
=C3=B8 is ø
=20 is ???
= is ???
How to do this (without just using gsub)?
You need to use a MIME parser, which should take care of removing the headers and getting rid of the quoted printable encoding. Depending on the layout of your email, body[text] might get you a lot more than you want. You need to either download the BODYSTRUCTURE and pick out the parts you want, or download the entire message (BODY[]) and use a MIME parser.
The decoding result is:
Hej
I må meget undskylde men jeg vil ikke købe produktet alligevel hvordan gør vi det...
Hans Nielsen.
Rørgade 65
1234 Gørlev
It seems that = is ... and =20 is "\n".