1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117:
| procedure TImportTIForm.SetDocType(s:string); var aResult:String; begin aResult := ''; if (Document.SupportsService('com.sun.star.sheet.SpreadsheetDocument')) then aResult := 'scalc'; if (Document.SupportsService('com.sun.star.text.TextDocument')) then aResult := 'swriter'; if (Document.SupportsService('com.sun.star.drawing.DrawingDocument')) then aResult := 'sdraw'; if (Document.SupportsService('com.sun.star.formula.FormulaProperties')) then aResult := 'smath'; if (aResult = '') then aResult := 'unknown';
p_Doc_Type:= aResult; end;
function TImportTIForm.ToOOPath(FilePath:String):String; var ReturnSTR : string; i : integer; begin ReturnSTR := 'file:///'; while (POS('\',FilePath)>0) do begin i := POS('\',FilePath); delete(FilePath,i,1); Insert('/',FilePath,i); end; ReturnSTR := ReturnSTR + FilePath; result := ReturnSTR; end;
function TImportTIForm.OpenOODoc(Filename:string):boolean; var ReturnValue : boolean; begin Filename := ToOOPath(Filename); try Document := Desktop.LoadComponentFromURL(Filename,'_blank',0,VarArrayCreate([0, - 1], varVariant)); ReturnValue := true; SetDocType('dummy'); except ReturnValue := false; end; result := ReturnValue; end;
function TImportTIForm.CreateOODoc(DocType:Integer):boolean; Var URL : String; ReturnValue : boolean;
begin Case DocType of 0: URL := 'private:factory/' + 'scalc'; 1: URL := 'private:factory/' + 'swriter'; 2: URL := 'private:factory/' + 'sdraw'; 3: URL := 'private:factory/' + 'smath'; else begin Result := False; exit; end; end; try Document := desktop.LoadComponentFromURL(URL,'_blank', 0, VarArrayCreate([0, - 1], varVariant)); ReturnValue := true; except ReturnValue := false; end; result := ReturnValue; end;
function TImportTIForm.SaveOODoc(Filename:string):boolean; Var VariantArr : Variant; ReturnValue : boolean; begin try VariantArr := VarArrayCreate([0, 0], varVariant); Document.StoreToURL(ToOOPath(Filename), VariantArr); ReturnValue := true; except ReturnValue := false; end; result := ReturnValue; end;
function TImportTIForm.CloseOODoc(Filename:string):boolean; begin Document.Close(True); end;
function TImportTIForm.GetOOCellContent(worksheetNr:Integer;aCol,aRow:integer):String; var sh,bm : Variant; begin sh := Document.Sheets.getByIndex(worksheetNr); bm := sh.getCellbyPosition(aCol,aRow); result := bm.getString; end;
function TImportTIForm.WriteOOCellContent(worksheetNr:Integer;aCol,aRow:integer;AString:String):boolean; var sh,bm,tc : Variant; begin sh := Document.Sheets.getByIndex(worksheetNr); bm := sh.getCellbyPosition(aCol,aRow); bm.setString(AString); end; |