Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Excel formatiing via Fox
Message
De
23/09/1999 11:11:39
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
23/09/1999 08:17:21
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00267917
Message ID:
00267995
Vues:
14
>I am trying to create spreadsheets via FoxPro into excel. I am able to get the data into the spreadsheets. The problem I am having is formatting the spreadsheet. I want to add underlines, subtotal, etc. The number ofrecords in my files constantly changes. So a formula that might fit in cell F35 on one day may need to be moved down to F60 or something the next day. This is what I have
>> so far.
>>
>> With objExcel
>>
>> .Sheets("DC").Activate
>> .Cells(1,1).select
>> .Selection.End(xlToRight).select
>> .selection.end(xldown).select
>>
>> This positions me at the end of the data block. I want to move down from here two or three cells and put a formula in place that will sum the entire column. I think I need to load the coordinates into a variable and add "two or three places" to that so it positions the cursor where I want the formula. How do I do that? Any ideas. Samples would greatly be appreciated


Instead of two moves check "SpecialCells" and "Region". Here is a sample that could help you (VFP5, so home()+samples is correct, modify it if VFP6).
USE home()+"samples\data\orders"
lcXLFile = "c:\temp\myxltest.xls"
COPY to (lcXLFile) type xl5
lnRows = reccount()
lnCols = fcount()
lcFormulaCell = _GetChar(lnCols)+ltrim(str(lnRows+3)) && 1 header + 2 choice
oExcel = createobject("excel.application")
WITH oExcel
  .Workbooks.Open(lcXLFile)
  WITH .ActiveWorkBook.ActiveSheet
    .Range(lcFormulaCell).Formula = ;
      "=SUM("+_GetChar(lnCols)+"2:"+;
      _GetChar(lnCols)+ltrim(str(lnRows+1))+")"
&& +1 is for we sent also header
  ENDWITH
  .visible = .t.
ENDWITH


* Return A, AA, BC etc noation for nth column
FUNCTION _GetChar
  LPARAMETERS tnColumn && Convert tnvalue to Excel alpha notation
  IF tnColumn = 0
    RETURN ""
  ENDIF
  IF tnColumn <= 26
    RETURN chr(asc("A")-1+tnColumn)
  ELSE
    RETURN 	_GetChar(int(iif(tnColumn % 26 = 0,tnColumn - 1, tnColumn) / 26)) + ;
      _GetChar((tnColumn-1)%26+1)
  ENDIF
Although R1C1 notation could be used in many properties A1 notation performs better (Personal opinion).
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform