E
E
Evgeny Ivanov2019-04-05 10:32:17
Delphi
Evgeny Ivanov, 2019-04-05 10:32:17

How to understand that the cell is empty (xlsreadwriteii 5)?

RAD Studio 10.1 Berlin.
I work with excel - xlsx. xlsreadwriteii component 5.
All data is being read, but there was a problem. xlsreadwriteii 5 cannot detect an empty cell.
When setting a condition. For example - if the cell contains text 1, do one thing, and if it is empty, do another.
Excel - Cell Format General. The numbers are saved as text.
So he (xlsreadwriteii 5) finds text 1, but there are no empty cells.

XLS:=TXLSReadWriteII5.Create(nil);
XLS.Filename:=ExtractFilePath(Application.ExeName)+'file.xlsx';
XLS.Read;
XLS[0].CalcDimensions;
//Еще код.....
//Читаем содержимое ячейки в переменную
NUMBER:=XLS[0].AsString[NUMBER_column,row];
//Узнаем длину строки
Form1.Memo1.lines.add('Длина строки NUMBER='+inttostr(Length(NUMBER)));
if (NUMBER='') then Form1.Memo1.lines.add('Пусто');
if (NUMBER='1')   then Form1.Memo1.lines.add('Единица');

If 1 is Unity. Everything is clear here.
If the cell is empty, then nothing will be displayed. Doesn't "catch." (
I find out the length of the string with an empty cell. The length of the string is 1. That is, the cell is empty, and the length of the string is 1!
This is the behavior of the program, without changing the excel file.
Let's now change the excel file.
I open the excel file. I manually change the cell from empty to 1 The
program "sees" 1. Which is obvious.
But now the program sees all empty cells in this row.
I changed one, and it somehow affected the "visibility" of all empty cells below.
That is, now the program works correctly But I did not change the format of the cells.I look again - the format of the cells is common.Numbers are saved as
text.Manually change the cell again from 1 to empty.Save.
The program "sees" and defines an empty cell (and everything below, of course). The string length is 0. Everything is as it should be.
Total.
Without manually opening the excel file, the program (xlsreadwriteii 5) does not detect empty cells.
With the opening of the excel file by hand and any change in the cell and saving the file, the program determines all empty cells.
This situation occurs with xlsreadwriteii 5. With OLE Excel did not notice this.
How to understand that the cell is empty (xlsreadwriteii 5)?
Why is this glitch happening?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kalapanga, 2019-04-05
@logpol32

So look at what you have in NUMBER after you have read an empty cell. There will most likely be some kind of LF or maybe TAB.

K
Konstantin Tsvetkov, 2019-04-05
@tsklab

View in the source files TXLSReadWriteII5how the cell is read.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question