* 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 * Handy wrapper for charting * select blahblah from blahblah into cursor crsXL * ... * lcRowRange = ltrim(str(reccount()+1)) && 1 for header * lcColumnRange = _GetChar(fcount()) * lcRangeEnd = lcColumnRange + lcRowRange * =_ExcelGraph("My Sheet Name", "A1:"+lcRangeEnd, xlBarStacked, xlColumns, ; * "My Chart Name", "Chart Title","Category Title",90,; * "Value Title",0,"Series Title") FUNCTION _ExcelGraph LPARAMETERS tcDataSheetName, tcRange, tnChartType, tnPlotBy, tcChartName, tcChartTitle, ; tcCategoryTitle, tnCategoryRotation, tcValuesTitle, tnValuesRotation, tcSeriesTitle WAIT window nowait "Charting " + tcChartName WITH oExcel .ActiveWorkBook.worksheets(tcDataSheetName).activate WITH .charts.add && Add chart in a new sheet * Required to fit different regional range delimiters * ie: "A4:H5;Z10:Z20" valid if regional setting is Turkish but not in US. * Should be "A4:H5,Z10:Z20" (not valid in Turkish setting) - Excel returns error * So instead of changing code per region Union ranges tcRange = [oExcel.Sheets("]+; tcDataSheetName+; [").range("]+; strtran(tcRange, ";", ["),oExcel.Sheets("]+; tcDataSheetName+; [").range("])+; [")] IF occurs(",",tcRange) = 0 toRange = &tcRange && Single range ELSE toRange = oExcel.Application.Union(&tcRange) && Multipl ranges ENDIF * Required to fit different regional range delimiters .SetSourceData(toRange, tnPlotBy) .Location(xlLocationAsNewSheet) .hastitle = .t. .haslegend = .t. .ChartType = tnChartType WITH .ChartTitle .caption = tcChartTitle .Shadow = .t. WITH .Border .Weight = xlHairline .LineStyle = xlAutomatic ENDWITH ENDWITH WITH .Axes(xlCategory).TickLabels .Font.Size = 8 .Orientation = xlTickLabelOrientationAutomatic ENDWITH * Set axis titles =_FormatAxis(xlCategory, tcCategoryTitle,tnCategoryRotation) && Set axis titles IF .Axes.count > 2 && Otherwise following formatting =_FormatAxis(xlSeries, tcSeriesTitle) && cause illegal operation (if chart is not 3D) ENDIF =_FormatAxis(xlValue, tcValuesTitle, tnValuesRotation) .Legend.Position = xlTop .Name = tcChartName ENDWITH ENDWITH FUNCTION _FormatAxis LPARAMETERS tnAxis, tcCaption, tnOrientation, tcFontName, tnFontSize, tlBold, tlItalic, tlUnderline, tlShadow IF type("tcCaption") = "C" and !empty(tcCaption) and type(".Axes(tnAxis)") = "O" && Not empty title and axis is a supported type IF type("tnOrientation") # "N" tnOrientation = 0 ENDIF IF type("tcFontName") # "C" or empty(tcFontName) tcFontName = "Arial" ENDIF IF type("tnFontSize") # "N" tnFontSize = 10 ENDIF WITH .Axes(tnAxis) .hastitle = .t. WITH .AxisTitle .Caption = tcCaption .Orientation = tnOrientation WITH .Font .Name = tcFontName .Size = tnFontSize .Bold = tlBold .Italic = tlItalic .Underline = tlUnderline .Shadow = tlShadow ENDWITH ENDWITH ENDWITH ENDIFCetin