Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File exported is corrupt. #16

Open
kenyong opened this issue Feb 25, 2014 · 5 comments
Open

File exported is corrupt. #16

kenyong opened this issue Feb 25, 2014 · 5 comments

Comments

@kenyong
Copy link

kenyong commented Feb 25, 2014

I export the data from MongoDB. Then I use "excel-export" to export the .xlsx file.
And I have found that some issues due to corrupt the excel file and display nothing.
Such as
-1 Some emoji characters can't not display and the excel alert "This file is corrupt!".
-2 Some unknown characters shown as '口'.

Due to these cases, I have tried this:
var temp = source.replace(/([\uE000-\uF8FF]|\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDDFF])/g, '');
var buf = iconv.encode(temp, 'UTF8');//return GBK encoded bytes from unicode string
var str = iconv.decode(buf, 'UTF8'); //return unicode string from GBK encoded bytes
return str;

Besides this, I also tried other methods.
But they have not solved this issue perfectly.

@m13
Copy link

m13 commented Feb 27, 2014

I had the same message error "This file is corrupt!" and I solved with:

var returnVar = new Buffer(excel.execute(conf), 'binary'); // cols & rows are utf-8
res.send(returnVar); // expressjs

I had the problem of the unknown characters (japanese) importing a CSV to the Excel, but not with this library.

@mitchellsimoens
Copy link

The solution that solved corrupt files for me was not to use the date type. This works:

conf.cols = [{
    caption:'string',
    type:'string'
},{
    caption: 'bool',
    type: 'bool'
},{
    caption:'number',
    type:'number'
}];
conf.rows = [
    ['foo', true, 123.456]
];

but as soon as I add date type column, Excel complains about file is corrupt:

conf.cols = [{
    caption:'string',
    type:'string'
},{
    caption: 'bool',
    type: 'bool'
},{
    caption:'number',
    type:'number'
},{
    caption:'date',
    type:'date'
}];
conf.rows = [
    ['foo', true, 123.456, new Date()]
];

@functionscope
Copy link
Owner

Excel stores date in OA format.

Check out the example in using excel-export.

You need to do a conversion in beforeCellWrite

beforeCellWrite:function(){ var originDate = new
Date(Date.UTC(1899,11,30)); return function(row, cellData, eOpt){ return
(cellData - originDate) / (24 * 60 * 60 * 1000); }

On May 5, 2015 3:38 PM, "Mitchell Simoens" [email protected] wrote:

The solution that solved corrupt files for me was not to use the date
type. This works:

conf.cols = [{
caption:'string',
type:'string'
},{
caption: 'bool',
type: 'bool'
},{
caption:'number',
type:'number'
}];
conf.rows = [
['foo', true, 123.456]
];

but as soon as I add date type column, Excel complains about file is
corrupt:

conf.cols = [{
caption:'string',
type:'string'
},{
caption: 'bool',
type: 'bool'
},{
caption:'number',
type:'number'
},{
caption:'date',
type:'date'
}];
conf.rows = [
['foo', true, 123.456, new Date()]
];


Reply to this email directly or view it on GitHub
#16 (comment)
.

@mitchellsimoens
Copy link

What junk. Why does it take care of that for you? It knows the type is date... So if the value is a Date object, take care of that.

I also had an issue that I was passing in an int when the column had string specified. Little bit of type checking would go a long way...

Planning on developing my own now. Started to patch a few things and am gonna give up. I'll do my own and maintain it internally.

@Getz85
Copy link

Getz85 commented Oct 21, 2015

Same problem here with a simple file (one column of type string), with no special characters.
I'm on Windows 7 64 with node v0.12.7 and Excel 2010.

I tried this solution (http://answers.microsoft.com/en-us/office/forum/office_2010-excel/the-file-is-corrupt-and-cannot-be-opened-error-on/93af59c1-946c-4f5f-83c1-bd6f58dbd94f?auth=1), but it doesn't work... So I guess it comes from the generation. Any help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants