Recent

Author Topic: Exporting ListView to Excel  (Read 4655 times)

fic

  • New Member
  • *
  • Posts: 14
Exporting ListView to Excel
« on: April 18, 2014, 05:35:50 pm »
Hi all,

I'm trying to export a Listview to an Excel2010-sheet.

Excel opens well, but then when I try to create the columnheaders, I got into problems

Look at the code below :
   {create the columns}
    for x := 0 to (lvGPMI.Columns.Count -1) do begin
      //ShowMessage(lvGPMI.Columns.Items
  • .Caption);

      tmp := lvGPMI.Columns.Items
  • .Caption;

      Sheet.Cells[1, (x + 1)] := tmp; //'haha';
      //Sheet.Cells[1, (x + 1)] := lvGPMI.Columns.Items
  • .Caption;

    end;

When I put the caption of the ListView in Excel, it appears as some Chinese characters.
When I replace the tmp with 'haha', all works just fine.
How come the ListView-caption is not accepted as normal text, and the 'haha' is?

I really would like to know an answer to that.

TIA,

fic.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Exporting ListView to Excel
« Reply #1 on: April 18, 2014, 05:52:42 pm »
Please, edit your post and close the code to tags
Code: [Select]
[code]because forum changes [indexes] to whatever.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

fic

  • New Member
  • *
  • Posts: 14
Re: Exporting ListView to Excel
« Reply #2 on: April 18, 2014, 06:19:17 pm »
Apparently :-(

Got any workaround suggestion? Or just an answer?

Thanx

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Exporting ListView to Excel
« Reply #3 on: April 18, 2014, 06:42:45 pm »
most likely the lcl utf8 support is getting in the way try to convert it to using utfdecode if memory serves me right.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

fic

  • New Member
  • *
  • Posts: 14
Re: Exporting ListView to Excel
« Reply #4 on: April 18, 2014, 06:50:34 pm »
Unfortunately, I tried that allready...
I'ts not happening.
Going berzerk....

wp

  • Hero Member
  • *****
  • Posts: 11915
Re: Exporting ListView to Excel
« Reply #5 on: April 18, 2014, 07:32:33 pm »
Quote
Got any workaround suggestion?
What Blaazen is trying to say is:
Write [ code] in front of "{create the columns]", and [ /code] after "end;" - then the forum software will leave the expressions in square brackets untouched. Please don't type the empty space after "[" - I have to insert it here otherwise the software will do it's own thing... Or select the code and click at the "#" button in the toolbar above the memo, this will add the [...] expression automatically.

fic

  • New Member
  • *
  • Posts: 14
Re: Exporting ListView to Excel
« Reply #6 on: April 18, 2014, 08:23:05 pm »
Thx, I will try this tomorrow morning.

Thank you guys!

Much appreciated :-)

fic.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Exporting ListView to Excel
« Reply #7 on: April 18, 2014, 09:09:21 pm »
Quoted fic's post and:
Code: [Select]
   {create the columns}
    for x := 0 to (lvGPMI.Columns.Count -1) do begin
      //ShowMessage(lvGPMI.Columns.Items[x].Caption);
      tmp := lvGPMI.Columns.Items[x].Caption;
      Sheet.Cells[1, (x + 1)] := tmp; //'haha';
      //Sheet.Cells[1, (x + 1)] := lvGPMI.Columns.Items[x].Caption;
    end;

fic

  • New Member
  • *
  • Posts: 14
Re: Exporting ListView to Excel
« Reply #8 on: April 19, 2014, 09:18:05 am »
Stupid me

I declared tmp as a string.
It should've been a Variant.
Everything works real fine now.
Thanks.

 

TinyPortal © 2005-2018