1

When I try to transfer the data, from my database, using a look up field to an Excel sheet, it completely changes the string.

Exemple:

Sheet.Cells[l,2]:=dmOrcamentos.ztBaseOrcamento.FieldByName('MP_DESC').Text;

Final data(the one that is showed in EXCEL):

䡃㠠〬‰䅓⁅〱㠰

In debuging mode it shows:

Sheet.Cells[l,2]:=dmOrcamentos.ztBaseOrcamento.FieldByName('MP_DESC').Text = <Error>

The result should be:

CH 2,00 SAE 1008

And if I use a normal string field, with special characters, it changes the special character.

Exemple:

Sheet.Range['B5'] := 'DESCRIÇÃO';

Final data(the one that is showed in EXCEL):

DESCRIÃÃO

The result should be:

DESCRIÇÃO

I use Lazarus 1.4.2 which is accompanied by FPC 2.6.4, Firebird 2.5 and Excel 2010. The DataBase has no encoding or, at least it shows NONE in Charset.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Will
  • 307
  • 4
  • 12
  • 2
    You've got Excel and the DB here. Try to isolate the problem. Start by throwing Excel away. What value does `dmOrcamentos.ztBaseOrcamento.FieldByName('MP_DESC').Text` have? Do you know how to debug? If so, then you'll be able to answer this question. Then you'll know the issue is with the DB. Where the data is stored as ASCII or UTF-8 but later interpreted as UTF-16 – David Heffernan Aug 04 '15 at 12:38
  • @DavidHeffern I did not think about the interpretation, I will take a look. I updated the question. – Will Aug 04 '15 at 12:52
  • @RBA I updated the question, take a look please – Will Aug 04 '15 at 12:53
  • We know nothing of how the data is stored in the DB, what encodings are using in your FPC code. Are you familiar with text encodings? – David Heffernan Aug 04 '15 at 13:07
  • FWIW, since these questions tend to remain on this server (almost?) forever, could you please indicate the exact version of Lazarus and FPC? People may know this now, but perhaps not in 2 years from now. – Rudy Velthuis Aug 04 '15 at 13:28
  • Have you checked if your SQL Dialect is 3 ? To use Brazilian Portuguese "ç" you may use it. Sei porque já passei por isso! – Leo Melo Aug 04 '15 at 13:33
  • @David: you are right. The Unicode values for `䡃㠠〬‰䅓⁅〱㠰` are `U+4843 U+3820 U+302C U+2030 U+4153 U+2045 U+3031 U+3830` or, as bytes, `$48 $43 $20 $38...` etc., and that is quite clearly, in ASCII, `CH 8,00 SAE 1008`. – Rudy Velthuis Aug 04 '15 at 13:36
  • http://stackoverflow.com/q/2241348/327083 – J... Aug 04 '15 at 13:38
  • @DavidHeffernan I don't know a lot about text encoding, but I think this should be the solution. I will try to learn a little more on the internet. Btw, updated the question – Will Aug 04 '15 at 13:38
  • @RudyVelthuis Ok, updated – Will Aug 04 '15 at 13:39
  • You still haven't told us what comes back from the DB. The question I asked in my very first comment. Is the issue with Excel or your DB access? – David Heffernan Aug 04 '15 at 13:39
  • See my comment to David. Your Chinese (?) interprets your data as double bytes (UTF-16), while interpreted in a simple single byte encoding (or ASCII, which is probably equivalent to none) the same bytes form the text "CH 8,00 SAE 1008". Please read the link @J... posted, especially the article that that page links to. – Rudy Velthuis Aug 04 '15 at 13:42
  • @LeoMelo I could not find the dialect, can you explain me the path? (acho melhor falar em inglês mesmo, pra não reclamarem) – Will Aug 04 '15 at 14:02
  • I'm going to give up at this point. You won't let me help you narrow this down. Good luck. – David Heffernan Aug 04 '15 at 15:58
  • Generally is a parameter of the Connection. Wich is the base class of your Connection? I generally use a TAdoConnection. (Eu uso firebird com Ado e lá tem o SQLDialect 1, 2 ou 3) – Leo Melo Aug 04 '15 at 17:15
  • I use ZeosDBO for connection. @LeoMelo (Acho que é isso que vc quer saber. Tentei procurar no componente, mas não achei) – Will Aug 05 '15 at 17:47

1 Answers1

1

You may check. Encoding iso 8959_1 for latin characters like "Ç".

Using ZeosDBO, assuming your connection is named Connection:

Connection.Properties.Add ('Codepage=ISO8859_1');
Connection.Properties.Add ('Dialect=3');

This will accept José, Calça, Cancões.

Hope this works!

Leo Melo
  • 196
  • 5
  • OK, now both DataBase and Connection are with dialect 3 and encoding 8859_1, but it still doesn't work. May the problem be with excel? Or maybe the database fields? Which got no encoding("NONE"). – Will Aug 06 '15 at 10:54
  • Excel would be the last thing to check. If it is possible alter the collate of a single column at your database, insert a value like DESCRIÇÃO and test it. At your dataset don´t forget to delete the TField associated. – Leo Melo Aug 06 '15 at 12:37