Spreadsheet.open in Rails gives this error "unknown encoding name - MACINTOSH" - ruby-on-rails

I am using Spreadsheet to parse xls files. It's working great. but today one of my user has uploaded a file and it's getting an error "unknown encoding name - MACINTOSH"
My code is:
book = Spreadsheet.open file_path
sheet1 = book.worksheet 0
This is the excel file which is getting the error:
https://www.dropbox.com/s/jv37pk5rpiy9259/testlisttextnonames2.xls
Can you guys please help me to solve this issue.

Running into the same problem. Here is the best i can deduce:
"Macintosh" is not a known encoding in Ruby 1.9+. Try opening a console and running "Encoding.find('Macintosh')". You'll get the same error.
So what is available? In the console: "Encoding.list". One of the options is MacRoman. I'm guessing this is a close second.
So if we change the mapping in lib/spreadsheet/excel/internals.rb for 10000 and 32768 to map to "MACROMAN", it should work.
Tested locally and it does.
I opened a pull request: https://github.com/zdavatz/spreadsheet/pull/51
Some reference links:
* https://en.wikipedia.org/wiki/Mac_OS_Roman
* http://bugs.python.org/issue843590

Related

All of a sudden R does not read my excel files

So today all of a sudden R does not read my excel files. I made absolutely no change on my computer.
My working directory is "C:/Users/Ilias Iliadis/OneDrive/Documents" (i got this with getwd() ).
This is the error message that is displayed: Error in read.xlsx.default("GerBiogas") : File does not exist.
GerBiogas is the file i am trying to load. I am absolutely sure it is in the correct folder and i spell it properly. The file is also in xlsx form. I unistalled and reinstalled R but the problem remains.
Do you have any idea was is going on? All of a sudden i cannot load any of my files.
I am trying to load it with this:
read.xlsx("GerBiogas")
i also tried to specify the path: DT <- read.xlsx("C:\Users\Ilias Iliadis\OneDrive\Documents\GerBiogas.xlsx")
Again it does not work. I am using R version 4.2.2.

How to avoid Excel "bad format error" when saving spreadsheet

Using PHPSpreadsheet saving XLSX format works OK running the default code
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save("filename.xlsx");
But if I want to have the user to select the target directory using
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="filename.xlsx"');
header('Cache-Control: max-age=0');
$writer = IOFactory::createWriter($spreadSheet, 'Xlsx');
$writer->save('php://output');
The file saves OK but Excel 2016 does not want to open it. Excel returns the following error
Excel Error
I looked through all documentation and posts but cannot find the solution.
Thanks !
Edit: Just in case, this solution does not work for me.
Edit 2: The sample provided Simple Download Xlsx works perfectly, but when doing a copy/paste for my spreadsheet, Chrome gives me a
Resource interpreted as Document but transferred with MIME type application/octet-stream
Edit 3: Used
ob_end_flush(); to clean any left over header in my code.
The file now saves OK, but needs repair when opening in Excel. Why ?
Thanks
Solution:
Bug from PhpSpreadsheet.
When using
header("Content-Type: application/vnd.ms-excel");
i.e. compatibility mode for Excel, the file opens OK.

Prestashop product upload with csv error

I am trying to upload csv file of products in prestashop. Below are the errors that I am getting :
No Name (ID: 61,1,Orous Women's A Line Dress,Home,1399,IN Reduced Rate (4%),0,0,,,,,D2_Yellow,,,,,,,,,,,2,,,,,,"Fabric: Crepe A-line
Exquisite style patterns Gentle machine wash, dry clean, do not
bleach",,,,,,,,,1,,,,http://www.spademark.com/1154X1500/orous/D2_Yellow-_1.jpg,,,,New,,,,,,,,)
cannot be saved
and
Property Product->name is empty
What am I doing wrong?
docs http://doc.prestashop.com/display/PS16/CSV+Import+Parameters
Please use this structure for successful upload:
"Enabled";"Name";"Categories";"Price";"Tax rule ID";"Buying price";"On sale";"Reference";"Weight";"Quantity";"Short desc.";"Long desc";"Images URL"
1;"Test";"1,2,3";130;1;75;0;"PROD-TEST";"0.500";10;"'Tis a short desc.";"This is a long description.";"http://www.myprestashop/images/product1.gif"

OpenCV header error (YAML)

Ok so I feel that I have finally successfully used the OpenCV libraries in my app, except for one thing...
My .yml files get generated correctly except the '%YAML:1.0' header at the top turns out like this '01%YAML:1.0'. The '01' infront of the header is causing this error (I think):
OpenCV Error: Parsing error (/var/mobile/Applications/53C6CBA3-15B7-436A-892B-2ECFA75B72CD/Library/DownloadedDescriptors/descriptors.yml(1): Valid XML should start with '<?xml ...?>') in icvXMLParse, file /Users/Dash/Documents/SmartServices/AirLink/ProjectGhost/FairfaxNewsDemo/opencv-2.3.1/OpenCV-2.3.1/modules/core/src/persistence.cpp, line 2163
Anyone know how to solve this issue?
Ok after looking into it a bit further I dont think it's the headers problem. My file always gets generated with '01' at the start.
Hmm...this is embarrassing. But it turns out that I had a 'print' statement lingering in the php file that helps generate my .yaml file, causing 0 and 1 to be added to the beginning of the document.
This meant that my file didn't start with '%YAML:1.0' as expected but '01%YAML:1.0'

Opening and decompressing an XML URL in Rails

I'm building a rails app that takes information about products from an XML datafeed hosted on a 3rd party server. This XML is sent gzipped, and I'm having serious difficulty in getting anywhere with it.
I've spent a fair bit of time with Google on this, but the results of my searching seem to be more about Sending Gzipped output rather than receiving a Gzipped input.
The closed I've come to a solution came from StackOverflow, but I'm still getting errors.
What I'm trying to do in the first instance is print the XML data to the browser, then I can start with the processing of it. Here's my current code:
def load_data
url = "http://xml.domain.com/datafeed/"
xml_input = Net::HTTP.get(URI.parse(url))
zstream = Zlib::Inflate.new
#xml_output = zstream.inflate(xml_input)
zstream.finish
zstream.close
end
The error I'm getting from it is:
Zlib::DataError in Cron/get datafeedController#load_data
incorrect header check
I guess this means that the data isn't in the format that is expected, but I can't find information about how to do this properly anywhere. Two things I've ruled out is that the URL is valid and the response is Gzipped, but I'm stuck with how to get past this.
Any help would be greatly appreciated :-)
Sorted!
file = Net::HTTP.get(URI.parse(url))
gz = Zlib::GzipReader.new(StringIO.new(file))
whole_xml = gz.read
Then to load into Hpricot to do the XML parsing:
hp = Hpricot(whole_xml)

Resources