Type xlsxHyperLink = Class
	Function Create(sheetName, file, xmlFile); overload;
	Begin
		sheetName_ := sheetName;
		file_  := file;
		xmlFile_ := xmlFile;
	End;

	class Function NewObject(sheetname, file);
	Begin
		xmlFile := file.WorkBook().GetSheetXmlfile(sheetname);
		return new xlsxHyperLink(sheetname, file, xmlFile);
	End;

	Function SetCellHyperLink(axis, link);
	Begin
		hyperlink := link;
		work_node := xmlFile_.FirstChildElement('worksheet');
		hyperlinks := work_node.FirstChildElement('hyperlinks');
		if not ifObj(hyperlinks) then begin
			insert_node := class(TSXml).GetWorkSheetPrevNode(work_node, 'hyperlinks');
			hyperlinks := work_node.InsertAfterChild(insert_node, 'element', 'hyperlinks');
		end;
		node := hyperlinks.FirstChildElement('hyperlink');
		while ifObj(node) do begin
			ref := node.GetAttribute('ref');
			if ref = axis then begin
				hyperlink_node := node;
				break;
			end;
			node := node.NextElement();
		end;
		hyperlink.Axis := axis;
		if hyperlink.LinkType = "location" then
		begin
			hyperlink.Location := hyperlink.LinkUrl;
		end
		else if hyperlink.LinkType = 'external' then
		begin
			relsfile := file_.WorkBook().GetSheetRelsFile(sheetName_);
			[id, target, rid] := class(TSXml).FindRelationshipRid(relsfile, hyperlink.LinkUrl);
			if target = "" then
			Begin
				id++;
				ridstr := 'rId' + inttostr(id);
				class(TSXml).AddRelationshipRid(relsfile, hyperlink.LinkUrl, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", ridstr, "External");
				hyperlink.Rid := ridstr;
			End
			else hyperlink.Rid := 'rId' + inttostr(rid);
		end
		hyperlink.LinkType := nil;
		hyperlink.LinkUrl := nil;
		if not ifObj(hyperlink_node) then
		begin
			hyperlinks.InsertEndChild(hyperlink.marshal());
		end
		else begin
			marshal := hyperlink.Marshal();
			class(TSXml).UpdateNode(node, marshal['attributes'], marshal['children']);	
		end
	End;

	Function GetCellHyperLink(axis);
	Begin
		hyperlinks := xmlFile_.FirstChildElement('worksheet').FirstChildElement('hyperlinks');
		if not ifObj(hyperlinks) then return "The cell has no hyperlink";
		node := hyperlinks.FirstChildElement('hyperlink');
		link := TOfficeObj('THyperLink');
		while ifObj(node) do begin
			ref := node.GetAttribute('ref');
			if ref = axis then
			begin
				location := node.GetAttribute('location');
				if location then
				begin
					link.LinkUrl := location;
					link.LinkType := 'location';
				end
				else begin
					link.LinkType := 'external';
					rid := node.GetAttribute('r:id');
					rels_file := file_.WorkBook().GetSheetRelsFile(sheetName_);
					target_node := class(TSXml).FindRelationship(rels_file, rid);
					if ifObj(target_node) then link.LinkUrl := target_node.GetAttribute('Target');
				end
				link.Tooltip := node.GetAttribute('tooltip');
				break;
			end
			node := node.NextElement();
		end;
		return link;
	End;

private
	file_; //TSExcelFile对象
	xmlFile_;//XmlFile对象
	sheetName_;

End;
