本人有几个问题要请教.(急)(100分)

  • 主题发起人 主题发起人 蓝色暇想
  • 开始时间 开始时间

蓝色暇想

Unregistered / Unconfirmed
GUEST, unregistred user!
在EXCEL里怎么把一个CHART和数据同时放在同一个SHEET里。
怎么去掉Chart图后面的线。
怎么控制柱状图之间的间距。

在EXCEL的CELLS里怎么调用自己的函数。
怎么在Delphi调用EXCEL的时候初始化EXCEL的宏
 
不是吧,让我这么失望,在大富翁这多人才的地方都没有人知道?
 
怎么控制柱状图之间的间距
双击chart,在serise中,将bar width调整为100%,bar offset调整为50%,如果还有间距,
请,拉伸chart的大小,即可。(我指的是在delphi中)

 
先看看这个贴子,
http://www.delphibbs.com/delphibbs/dispq.asp?lid=691080
再去去这个网站,或许对你有所帮助.
另外,你只要知道了EXCEL中宏的用法与在DELPHI中有哪些不同,再将自己的要求在EXCEL中宏
中做一遍,再打开它的代码读读,你不就知道它是怎么做出来的了,再改成DELPHI的不就行了.
我就是这样做的,不清楚的,先开EXCEL,建立宏,看代码,再改成自己在DELPHI中的控制码.
 
unit MainForm;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OleServer, StdCtrls, Excel97, Buttons;

type
TMain = class(TForm)
ExcelApplication1: TExcelApplication;
WkBk: TExcelWorkbook;
WS: TExcelWorksheet;
Chart1: TExcelChart;
InlineChartBtn: TButton;
ChartPageBtn: TButton;
CloseBtn: TBitBtn;
PivotTableBtn: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure InlineChartBtnClick(Sender: TObject);
procedure ChartPageBtnClick(Sender: TObject);
procedure CloseBtnClick(Sender: TObject);
procedure PivotTableBtnClick(Sender: TObject);
procedure ExcelApplication1WorkbookBeforeClose(Sender: TObject; var Wb,
Cancel: OleVariant);
private
lcid: integer;
procedure EnterData;
procedure SetUpChart;
end;

var
Main: TMain;

implementation

{$R *.DFM}

uses ComObj, ActiveX;

procedure TMain.FormShow(Sender: TObject);
begin
{ No need to start Excel ourselves, since the ExcelApplication's AutoConnect
property is True }
lcid := GetUserDefaultLCID;
ExcelApplication1.Visible[lcid]:=True;

{ Create a new workbook }
{ The TOleEnum cast in the next line just prevents compiler range warnings }
WkBk.ConnectTo(ExcelApplication1.Workbooks.Add(TOleEnum(xlWBATWorksheet), lcid));
WS.ConnectTo(WkBk.Worksheets[1] as _Worksheet);
WS.Name := 'Data';
EnterData;
end;

procedure TMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
WS.Disconnect;
WkBk.Disconnect;
ExcelApplication1.Disconnect;
end;

procedure TMain.CloseBtnClick(Sender: TObject);
begin
Close;
end;

procedure TMain.ChartPageBtnClick(Sender: TObject);
var
SheetType: OleVariant;
begin
SheetType := TOleEnum(xlChart); // cast to avoid compiler range warnings
Chart1.ConnectTo(Wkbk.Sheets.Add(EmptyParam, EmptyParam, 1, SheetType, lcid) as _Chart);
Chart1.Name := 'Chart';
SetUpChart;
end;

procedure TMain.EnterData;
var
Row: integer;
ColumnTitles: olevariant;
begin
ExcelApplication1.ScreenUpdating[lcid] := False;
try
{ Using the Range object, you can enter one cell at a time ... }
WS.Range['B1', 'B1'].Value := 'Sample test scores';
WS.Range['A1', 'A1'].EntireRow.Interior.Color := clGray;
with WS.Range['B1', 'B1'].Font do
begin
Size := 22;
Name := 'Times New Roman';
FontStyle := 'Bold';
end;
WS.Range['A2', 'A2'].Value := 'Test';

{ Or several cells at once }
WS.Range['B3', 'E10'].Value := '=TRUNC(RAND()*10)';
WS.Range['B3', 'E10'].Font.Name := 'Courier New';

{ The Cells object allows you to access cells using row and column variables }
for Row := 3 to 10 do
WS.Cells.Item[Row, 1].Value := 'Test ' + IntToStr(Row - 2);

{ You can also use variant arrays, like this }
ColumnTitles := VarArrayOf(['Molly', 'Dolly', 'Polly', 'Holly']);
WS.Range['B2', 'E2'].Value := ColumnTitles;

finally
ExcelApplication1.ScreenUpdating[lcid] := True;
end;
end;

procedure TMain.InlineChartBtnClick(Sender: TObject);
var
ChObj: ChartObject;
begin
ChObj := (WS.ChartObjects(EmptyParam, lcid) as ChartObjects).Add(0, 170, 400, 250);
{ The following cast is essential! Without it, any attempt to use
the Chart object with early binding fails. }
Chart1.ConnectTo(ChObj.Chart as _Chart);
SetUpChart;
end;

procedure TMain.PivotTableBtnClick(Sender: TObject);
var
PT: PivotTable;
After: OleVariant;
begin
After := WkBk.Worksheets['Data'];
WS.ConnectTo(WkBk.Worksheets.Add(EmptyParam, After, 1, EmptyParam, lcid) as _WorkSheet);
WS.Name := 'Pivot table';
WS.Range['A2', 'A2'].Activate;
WS.PivotTableWizard(xlDatabase, 'Data!R2C1:R10C5', EmptyParam,
'PivotTable1', EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, lcid);
PT := WS.PivotTables('PivotTable1', lcid) as PivotTable;
PT.AddFields('Molly','Dolly', EmptyParam, EmptyParam);
(PT.PivotFields('Test') as PivotField).Orientation := xlDatafield;

{ Add heading }
WS.Range['B1', 'B1'].Value := 'Test scores: Molly and Dolly';
WS.Range['B1', 'B1'].EntireRow.Interior.Color := clGray;
with WS.Range['B1', 'B1'].Font do
begin
Size := 22;
Name := 'Times New Roman';
FontStyle := 'Bold';
end;
end;

procedure TMain.SetUpChart;
var
DataSheet: _Worksheet;
Ax: Axis;
Rnge, ChType: OleVariant;
begin
Datasheet := WkBk.Worksheets['Data'] as _Worksheet;
Rnge := Datasheet.Range['A2','E10']; // the data range, including titles
ChType := TOleEnum(xl3DColumn);
Chart1.ChartWizard(Rnge, ChType, EmptyParam, xlColumns, 1, 1, True,
WS.Range['B1', 'B1'].Text, // The chart title
'Test', 'Scores', EmptyParam, lcid);
Ax := Chart1.Axes(xlValue, xlPrimary, lcid) as Axis;
Ax.AxisTitle.Font.FontStyle := 'Italic';
end;



procedure TMain.ExcelApplication1WorkbookBeforeClose(Sender: TObject;
var Wb, Cancel: OleVariant);
begin
{ Stop DisplayAlerts to avoid being prompted to save before quitting. }
ExcelApplication1.DisplayAlerts[lcid] := False;
end;

end.
看看,参考参考。
 
问题还不少,还好还剩第一个问题没人回答!那就交给我吧!
关于怎么把一个CHART和数据同时放在同一个SHEET里?
你用achat:=asheet.chatobjects.add(100,100,200,200);及series:=achat.chat.seriescollection;
可以创建一个长为100.宽为200的统计图,其中asheet等都是定义的variant变量。
再用类似series.add('sheet1!R1C1:R2C2',true);语句即可通过sheet的数据画出相应统计图。
接下来,用asheet.saveas('c:/yb.xls');语句将数据存为Excel格式的文件,再把该文件Insert到
OleContainer中即可,OleContainer1.createobjectfromfile('c:/yb.xls',false); 一切至此OK!

2>
 
接受答案.我已分配了分,希望大家继续支持.
不过你们都还没有完全理解我的意思.
去掉Chart后面的线和间距,都是指在DELPHI里控制EXCEL中动态产生的图表.
不是在DELPHI中的chart.
在EXCEL中调用自己的函数。是指我在一个CELLS单元中输入公式([printdate])当然这不是
EXCEL的公式,怎么像EXCEL中一样的显示公式和内容.
 
I encounder a problem,
if there are 2 or 3 WorkSheets in Excel WorkBook.
I want to move a chart to sheet3,
eg
Excel_workbook.ActiveChart.Location(xlLocationAsObject, 'Sheet3');

but it is not work, the chart is still in first sheet.
 
后退
顶部