Type xlsxShape = Class
	///缺省构造函数
	Function Create(sheet,excel); overload;
	Begin
		excel_ := excel;
		sheetName_ := sheet;
		zipfile_ := excel.Zip();

		drawing_id := excel_.WorkBook().GetSheetDrawing(sheetName_);
		// drawingN.xml
		drawingXmlObj_ := excel_.WorkBook().GetXmlFileObj('xl/drawings/drawing' $ drawing_id $ ".xml");
	End;

	class Function NewObject(sheet, excel);
	Begin
		o := excel.WorkBook().GetSheetObj(sheet);//sheet存在
		if not ifObj(o) then return 0;
		return new xlsxShape(sheet, excel);
	End;

	Function AddShape(topLeft, bottomRight, shapeType, format);
	Begin
		[err1, col1, row1] := excel_.CellNameToCoordinates(topLeft);
		[err2, col2, row2] := excel_.CellNameToCoordinates(bottomRight);
		if err1 or err2 then return 'Invalid params.';

		o := TOfficeObj('TtwoCellAnchor');
		o.XFrom.Col := col1;
		o.XFrom.ColOff := format.BegColOff ? format.BegColOff : 0;
		o.XFrom.Row := row1;
		o.XFrom.RowOff := format.BegRowOff ? format.BegRowOff : 0;
		o.XTo.Col := col2;
		o.XTo.ColOff := format.EndColOff ? format.EndColOff : 0;
		o.XTo.Row := row2;
		o.XTo.RowOff := format.EndRowOff ? format.EndRowOff : 0;

		o.Pic.NodeName := 'xdr:sp';
		o.Pic.Macro := '';
		o.Pic.Textlink := '';
		setSpNvSpPr(o.Pic.NvPicPr, shapeType);
		setSpSpPr(o.Pic.SpPr, shapeType);
		setSpStyle(o.Pic.Style);
		setSpTxBody(o.Pic.TxBody, format);

		node := drawingXmlObj_.FirstChildElement('xdr:wsDr').InsertEndChild(o.Marshal());
	End;

private

	Function getShapeInfo();
	Begin
		return array(
			'rect': ('name': '矩形'),
			'roundRect': ('name': '矩形: 圆角'),
			'mathMinus': ('name': '减号'),
			'ellipse': ('name': '椭圆'),
				);
	End

	Function setSpNvSpPr(obj, shapeType);
	Begin
		obj.NodeName := 'xdr:nvSpPr';
		obj.CNvPr.ID := class(TSXml).GetcNvPrID(drawingXmlObj_);
		obj.CNvPr.Name := (getShapeInfo()[shapeType]['name'] ?: '') $ ' ' $ obj.CNvPr.ID;
		obj.CNvPr.ExtLst.Ext.Uri := '';
		obj.CNvPr.ExtLst.Ext.Xmlns16 := 'http://schemas.microsoft.com/office/drawing/2014/main';
		obj.CNvPr.Replace(array("pic:": "xdr:"));
		obj.CNvSpPr := true;
	End

	Function setSpSpPr(obj, shapeType);
	Begin
		obj.XFrm.Off.X := 0;
		obj.XFrm.Off.Y := 0;
		obj.XFrm.Ext.Cx := 0;
		obj.XFrm.Ext.CY := 0;
		obj.PrstGeom.Prst := shapeType;
		obj.PrstGeom.AvLst := true;
		obj.NodeName := 'xdr:spPr';
	End

	Function setSpStyle(obj);
	Begin
		obj.LnRef.Idx := 2;
		obj.LnRef.SchemeClr.Val := 'accent1';
		obj.LnRef.SchemeClr.Shade := '50000';
		obj.FillRef.Idx := 1;
		obj.FillRef.SchemeClr.Val := 'accent1';
		obj.EffectRef.Idx := 0;
		obj.EffectRef.SchemeClr.Val := 'accent1';
		obj.FontRef.Idx := 'minor';
		obj.FontRef.SchemeClr.Val := 'lt1';
	End

	Function setSpTxBody(obj, format);
	Begin
		obj.BodyPr.VertOverflow := 'clip';
		obj.BodyPr.HorzOverflow := 'clip';
		obj.BodyPr.RtlCol := 0;
		obj.BodyPr.Anchor := 't';

		if istable(format.ExtNodes) then
		begin
			obj.ExtNodes := format.ExtNodes ?: array();
		end
		else begin
			obj.P.PPr.Algn := 'l';
			obj.P.EndParaRPr.Lang := 'zh-CN';
			obj.P.EndParaRPr.AltLang := 'en-US';
			obj.P.EndParaRPr.SZ := '1100';
		end
	End

private
	sheetName_:string; //sheet名称
	excel_;//TSExcelFile对象
	zipfile_;
	drawingXmlObj_;
End;
