Quick way to compare stringgrid cells !

Hi All

I have 2 "Excel" spreadsheets with exactly the same formatting and columns but different data.
I need to process "Spreadsheet 1" and "Spreadsheet 2" and
create "Spreadsheet 3" (only the new cells and changed cells)

The data is for products and prices.
The idea is to create a new spreadsheet 3 with exactly the same format etc
from the spreadsheet 1 and spreadsheet 2.

"Spreadsheet 1" is old data
(eg price data from 2014)

"Spreadsheet 2" is new data
(eg price data from 2015)

"Spreadsheet 3" is the data that is different
(cells that have new values / changed values)

e.g. the price cell has changed from 1.20 to 1.25
e.g. there is a new product code

I have to process many thousands of data lines so efficiency is very important.

The data is read from each spreadsheet into separate string grids
"olddata" stringgrid, "newdata" stringgrid.

Is there a quick way to process this efficiently using TAdvStringGrid ?

Many thanks in advance for any help and guidance.



Sorry, there is currently not a built-in feature that could compare grid contents.
A possible implementation would be by using two grid instances, load the spreadsheet content in each of these grids and then write a loop over all cells of both grids to compare contents, i.e.

for x := 0 to grid1.ColCount - 1 do
  for y := 0 to grid1.RowCount - 1 do
     if grid1.Cells[x,y] <> grid2.Cells[x,y] then 
       // dfifference found

Hi Bruno,

j don't know wich vcl Kamran's installed, but (for me) a good solution to compare two or more xls(x) files is to work with flexcel.



Hi Daniele

I have flexcel vcl.

So how would that be possible with flexcel?

do you have an example ?

thank you


Hi Kamran,

in very very easy way (is the way j use to compare ... so sorry if this is not a fastest way or best one) consider to use flexcel version 6.


Xls1        : TXlsFile;    // First file

Xls2        : TXlsFile;   // Second

NewFile   : TXlsFile; // NewOne

In form create event you need to create the worksheet




Now you need to load the sheet (Xls(x) file)



Now you have the two excell file sotored in the grid with images, charts and so on.

Note that the two files stored in Xls1 and Xls2 are already in own grid so if yours files are the same and change are only in the cells value, with a simple loop you can find and store the difference in the new file.

Compare the cells value

if Xls1.CellValue(Row,Col)<>Xls2.CellValue(Row,Col) do Write your new row in newfile.

When you close the form,




Anyway you can get more help and better info at


and in the folder


where you can find MainDemo that is great techer.

Hope to be helpful.

Have a good evening,


Bruno and Daniele

thank you !