|
Hi to all,
I am using this code to read the office 2007 excel(.xlsx) file but it throws exception unknown file format.There is any update available of this project for office 2007.
Thanks,
Amar
|
|
|
|
|
Hi
I'm trying to write a small app to scan directories and find documents with embeded links or VBA code. I've tried using office interop but find alot of issues with it. This approach looks like just the job, just one small problem; When I click on a node in the tree (VBA or OLE info for example) the text that is displayed in the 'TextView' is not readable, it looks like an encoding issue but I can't where to change it. Has anyone come across this issue and managed to fix it?
Thanks
D
|
|
|
|
|
I don't think this has come up yet, but the program seems to be treating xls spreadsheets made by OpenOffice oddly. In particular, it's truncating numbers at the decimal randomly. Try opening http://sinbios.org/test.xls first in a spreadsheet application, and then in the supplied program, and you'll see that many of the numbers are truncated. Note that these numbers were inputted by hand, not using formulae. Perhaps they're being mistakenly cast into int somewhere?
|
|
|
|
|
Found the issue, turns out DecodeRK() in Record.cs returned num as an int if isFloat is false, and obviously the isFloat test is returning false for some values that should be true. Since for me it doesn't matter if integers are returned as doubles, I just changed the type of num from int to double even when isFloat is false.
|
|
|
|
|
Hi Liu Junfeng,
Absolutely this is a useful to get rid of Com-Ecel, but i have few issues in using this lib, those are, reading cell-value and cell-comment using named-cell. can you help me out in this regard....
I think mostly the answer is, you are not supporting this feature......but any ho...let me know any possibility..
Thanks for the great library.....
Mukthesh
|
|
|
|
|
Hi Liu,
After downloading your code and turning it into DLLs, I tried it out. It works very well with a single workbook but not with the next 180 of them. This is the situation: I have a SharePoint library with both .xls and .xlsx, a total of 181. They get downloaded into memory, including their streams, and I iterate through them leaving the xlsx out. As the program goes to each workbook and your code checks the header, the check fails. The bytes starting from the second workbook don't match the ones specified in your code. Now, the problem it that it works for the first file regardless of what file is the first. Do you have any ideas?
Thanks,
humble.apprentice
|
|
|
|
|
I facing the same issue, any solution for this ?
|
|
|
|
|
Firstly .xlsx file is not supported. If the file is .xls and still get "File header not recognized." message, maybe it is other versions of Compound Document. You can try comment this line
if (!doc.CheckHeader()) return null;
I am happy to work with people doing great projects.
|
|
|
|
|
Hi,
Yes, I know that xlsx is not supported, the 180 docs I mention where only xls. Any ideas?
Thanks,
humble.apprentice
|
|
|
|
|
After downloading the source I get an application where I expected a .dll (assembly) code. Maybe its misspacked?
|
|
|
|
|
Just switch the 'output type' from 'windows application' to 'class library' in the project's properties and you will get a dll.
|
|
|
|
|
Hi... Is there any way to edit the cells?
I mean, also without the nasty Interop?
Open mind for a different view.
|
|
|
|
|
Hi! I tried to see color of cells in test application but I couldn't to see. Can someone tell me why? Thank you very much, Andriy
|
|
|
|
|
I've a problem when a try to open some excel files :
sometimes, somes cells uses a user-defined format. For exemple a cell has a numeric value (1234567) but the user-defined format is (0# ## ## ##). So the value shown in excel is for exemple "01 23 45 67".
Is there a way to retreive this user-defined format with this library ?
thanks in advance
|
|
|
|
|
Hi
I'm using heavy use of your library, but I'm having problems with formulas. Someones are decoded and others not.
Is it possible to get the formula text, not the result?. I don't need the result, only read the cell with the formula as is ( ie =A1 ).
For the decoded formulas, I can use StringRecord property, but for the undecoded ones, the property value is null.
In Formula.cs you define public Byte[] FormulaData; . Do I need to parse the byte array acording to the Excel File definition?. This would be overkill for me beacuse I only need the formula text
Thanks in advance
|
|
|
|
|
Hello
I'm using your library a works like a charm.
The only drawback is that reading cell values with spanish characters like Ñ or é returns a character '?' instead of the correct value.
Is there a workaround for this?. I was using a propietary library for reading excel files but I'd prefer to use yours
Greetings from Spain
|
|
|
|
|
After digging through the source code I found the problem.
The encoding class used to read the bytes from the excel file was using an Encoding.ASCII, so, it was impossible to decode characters like É ( ASCII C9 in windows 1252 page chars table ). After changing to UTF-7, it works now
If anyone have the same problem, the file to change is Record.cs.
The function name is
ReadString(BinaryReader reader, int lengthbits, out BinaryReader continuedReader)
and the line is 97
Original
Encoding encoding = Encoding.ASCII;
and now corrected
Encoding encoding = Encoding.UTF7;
Anyway, thanks for this fantastic library
|
|
|
|
|
Many thanks for an outstanding & useful reply to support this library for unicode format.
|
|
|
|
|
Hi
As Funeral posted early in this thread (See page 2, entry "for managed accents" ), if you want to make the code really portable, use
Encoding encoding = Encoding.Default;
This way, you use the default codepage of the computer.
Be aware that this libreay DOES NOT SUPPORT Shared Formula cells, nor complex formula expressions.
Anyway it's an impressive library and free
|
|
|
|
|
I got error on Below line That --Object reference not set to an instance of an object.
string strFile = @"D:\Govind\matrix-format.xls";
Stream fileStream = File.OpenRead(strFile);
Workbook book = new Workbook();
book.Open(fileStream);
Worksheet sheet = book.Worksheets[0];
int row = 1;
int col = 0;
string ID = sheet.Cells[row, col].StringValue;--- got Error on this line
Regards,
Govind Bhanushali.
|
|
|
|
|
row and col index all starts with 0.
If a blank cell is not filled, it is null.
|
|
|
|
|
Hi!
Excellent little piece of code you have, thanks for that.
One question though:
I use the ExcelReader to read large amounts of data and I have noticed that every now and then the reader seems to read DateTime values incorrectly
<br />
item.StopTime = sheet.Cells[345, 1].DateTimeValue;<br />
<br />
In the example above the reader will falsely read the cell as "2007-06-29 00:00:00" and my data will run completely off the charts.
Am I using it incorrectly in any way or is there a fix coming up?
Thanks!
/Olle
|
|
|
|
|
In the function ReadString() found in SubRecords\Record.cs, the built-in function PeekChar() fails whenever the char being peeked upon is not Ascii or too big to fit in a char data type. PeekChar() probably assumes that all chars are Ascii. To fix this, I changed the first few lines to:
public string ReadString(BinaryReader reader, int lengthbits, out BinaryReader continuedReader)
{
Stream strem = reader.BaseStream;
if (strem.Position >= strem.Length)
{
// do something
}
....
}
The original text was:
public string ReadString(BinaryReader reader, int lengthbits, out BinaryReader continuedReader)
{
if (reader.PeekChar() == -1)
{
// do something
}
....
}
|
|
|
|
|
There are several easy ways to update this code to make it more readable and functional as well as perform better.
1) Always try to avoid using string concatenation. Strings in C# are immutable, and string + string + string requires allocating 2 new temporary strings. There's really no reason for AddWithComma to be as complicated and slow as your implementation. Just do this:
private string AddWithComma(string strSource,string strAdd)
{
return String.Format("{0}, {1}", strSource, strAdd );
}
2) Many of your functions look like this:
try {
} catch( Exception ex ) {
throw ex;
}
That's completely redundant. If all you plan to do with the exception is throw it, then don't catch it in the first place.
3) Many of your variables look like this:
private bool _blnKeepConnectionOpen=false;
public KeepConnectionOpen {
get { return _blnKeepConnectionOpen; }
set { _blnKeepConnectionOpen = value; }
}
This code is also completely redundant. If all you do is pass through the value, just make the variable public in the first place. Also, if you are going to use some form of Hungarian notation, consider using standard Hungarian (bKeepConnectionOpen, not blnKeepConnectionOpen). Also, why do you name your private variables in Hungarian-ish style and then not have the public properties use the same notation? It's confusing.
4) Don't ever catch and drop exceptions unless you have a very good reason to.
public String[] GetExcelSheetNames()
{
try {
// do the work
}
catch() {
return null;
}
}
Why did you do that? Anything that failed will just die silently, which is no help to anyone.
Please consider cleaning up your code before releasing it publicly. Readability and maintainability is as important as functionality.
|
|
|
|
|
I searched the code files with: AddWithComma, KeepConnectionOpen, GetExcelSheetNames, but nothing found.
Why you post this here?
|
|
|
|