Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating cool reports as Excel sheets
Message
From
07/04/2010 09:31:56
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
06/04/2010 23:16:31
General information
Forum:
Visual FoxPro
Category:
Third party products
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01458478
Message ID:
01459145
Views:
84
>>>How did you find that out?
>
>>How did I found out? I don't know, I knew it for a long time I didn't even think how I happened to learn it:) Actually I have posted another version of that code years ago:
>>Re: Drill down in excel Thread #1031781 Message #1032103
>>
>>Looking at title and your "drill down" I see that my main problem was in understanding what you want:)
>>
>>PS: It is PasteSpecial doing the job by the way. I read the documentation once upon a time and as I remember you could paste everyting, just values etc.
>>Cetin
>
>Ok, a few problems:
>
>1) A customer's ID is "138" because the client's name is "Bodega 138". (Notice how old fashioned DacEasy accounting is that it doesn't use meaningless numeric PK's). Excel looks at "138" and interprets it as a numeric 138. Not so bad, just format column as Text. Fine if you are not doing anything else with the spreadsheet.
>
>2) A salesperson's ID is "MAR1" because his last name is "Marin". Excel looks at "MAR1" and thinks it means March 1. Here forrmating the column as Text renders March 1 as number 40238 so we need another approach. I tried TYPE DELIMITED WITH TAB which places the string in quotes, with same results. If it was just this case we could do search and replace in Excel but we need a generic solution.
>
>The problems originate because PasteSpecial makes mistakes while interpreting the pasted string of characters. If we could make it accept a piece of string literally!
>
>Any suggestions?
>
>TIA,
>
>Alex
CREATE CURSOR xx (AccountId c(10), CompanyName c(30), maxAmt y)
INSERT INTO xx VALUES ('138', 'Bodega 138', 1000)
INSERT INTO xx VALUES ('MAR1', 'Marmaris Yacht&Sailing', 2000)
INSERT INTO xx (AccountId, CompanyName, maxAmt) ;
SELECT cust_id, Company, maxordamt FROM (_samples+'Data\customer')

Select AccountId as AccountID,CompanyName, maxAmt FROM xx ;
  into Cursor myCustomers

#include "xlConstants.h"
oExcel = Createobject("excel.application")
With oExcel
  .Workbooks.Add
  .Visible = .T.
  PasteAtLocation(oExcel, 'myCustomers','A1','Customers')
  .ActiveWorkbook.ActiveSheet.UsedRange.Columns(1).NumberFormat = '@'
Endwith

Function PasteAtLocation && Paste cursor content at given range and name the range
  Lparameters toExcel, tcAlias, tcRange, tcRangeName
  Local lcTemp,ix,lcHeaders
  lcTemp = Sys(2015)+'.tmp'
  Select (m.tcAlias)
  Copy To (m.lcTemp) Type Delimited With "" With Tab
  lcHeaders=''
  For ix=1 To Fcount()
    lcHeaders = m.lcHeaders +  Iif(Empty(m.lcHeaders),'',Chr(9)) + Field(m.ix)
  Endfor
  _Cliptext = m.lcHeaders + Chr(13) + Chr(10) + Filetostr(m.lcTemp)
  Erase (lcTemp)
  With toExcel.ActiveWorkBook.ActiveSheet
    .Range(m.tcRange).PasteSpecial()
    toExcel.Selection.Name = m.tcRangeName
    .Range(m.tcRangeName).Rows(1).Orientation = 90
  Endwith
Endfunc
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform