Type xlsxPageLayout = Class
	Function Create(sheetobj, file, xml); overload;
	Begin
		sheet_ := sheetobj;
		file_  := file;
		xmlFile_ := xml;
	End;

	Function SetPageLayout(sheet, pageLayout);
	Begin
		marshal := pageLayout.Marshal();
		work_node := xmlFile_.FirstChild('worksheet');
		node := work_node.FirstChild('pageSetUp');
		if ifObj(node) then work_node.DeleteChild(node);
		workbook_xml := file_.WorkBook().GetXmlFileObj('xl/workbook.xml');
		workbook := workbook_xml.FirstChildElement('workbook').FirstChildElement('sheets').FirstChildElement('sheet');
		if not ifObj(workbook) then return array(1, 'workbook error!');
		while ifObj(workbook) do
		Begin
			sheet_name := workbook.GetAttribute('name');
			if sheet_name = sheet then
			Begin
				rid := workbook.GetAttribute('r:id');
				break;
			End
			workbook := workbook.NextElement();
		End
		if not ifnil(marshal['attributes']['firstPageNumber']) then marshal['attributes']['useFirstPageNumber'] := 1;
		marshal['attributes']['r:id'] := rid;
		work_node.InsertEndChild(marshal);
		return array(0, '');
	End;

	Function GetPageLayout();
	Begin
		node := xmlFile_.FirstChild('worksheet').FirstChild('pageSetUp');
		if not ifObj(node) then return array(1, '<node>: pageSetUp not found');
		marshal := node.Marshal()[0];
		page_layout := TOfficeObj('TPageLayout');
		page_layout.Scale := marshal['attributes']['scale'];
		page_layout.FitToWidth := marshal['attributes']['fitToWidth'];
		page_layout.FitToHeight := marshal['attributes']['fitToHeight'];
		page_layout.PaperSize := marshal['attributes']['paperSize'];
		page_layout.Orientation := marshal['attributes']['orientation'];
		page_layout.BlackAndWhite := marshal['attributes']['blackAndWhite'];
		page_layout.FirstPageNumber := marshal['attributes']['firstPageNumber'];
		page_layout.CellError := marshal['attributes']['errors'];
		page_layout.CellComments := marshal['attributes']['cellComments'];
		page_layout.Draft := marshal['attributes']['draft'];
		return page_layout;
	End

	class Function NewObject(sheetname, file);
	Begin
		o := file.WorkBook().GetSheetObj(sheetname);
		xml := file.WorkBook().GetSheetXmlfile(sheetname);
		if not ifObj(o) then return 0;
		return new xlsxPageLayout(o, file, xml);
	End;

private
	file_; //TSExcelFile对象
	sheet_;//XmlSheet对象
	xmlFile_; //sheet对应的xml对象
End;
