{"id":19535664,"url":"https://github.com/miyako/4d-plugin-office-automation","last_synced_at":"2026-04-15T20:04:36.656Z","repository":{"id":147172403,"uuid":"368815984","full_name":"miyako/4d-plugin-office-automation","owner":"miyako","description":"instruct Word and Excel to open and close documents","archived":false,"fork":false,"pushed_at":"2023-08-16T04:11:33.000Z","size":37129,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-26T04:16:23.568Z","etag":null,"topics":["4d-plugin"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/miyako.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-19T09:35:16.000Z","updated_at":"2024-08-27T04:57:36.000Z","dependencies_parsed_at":"2025-01-09T01:34:52.546Z","dependency_job_id":null,"html_url":"https://github.com/miyako/4d-plugin-office-automation","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/miyako/4d-plugin-office-automation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miyako%2F4d-plugin-office-automation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miyako%2F4d-plugin-office-automation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miyako%2F4d-plugin-office-automation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miyako%2F4d-plugin-office-automation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miyako","download_url":"https://codeload.github.com/miyako/4d-plugin-office-automation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miyako%2F4d-plugin-office-automation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31857626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"ssl_error","status_checked_at":"2026-04-15T15:24:39.138Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["4d-plugin"],"created_at":"2024-11-11T02:19:29.235Z","updated_at":"2026-04-15T20:04:36.638Z","avatar_url":"https://github.com/miyako.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"![version](https://img.shields.io/badge/version-19%2B-5682DF)\n![platform](https://img.shields.io/static/v1?label=platform\u0026message=mac-intel%20|%20mac-arm%20|%20win-64\u0026color=blue)\n[![license](https://img.shields.io/github/license/miyako/4d-plugin-office-automation)](LICENSE)\n![downloads](https://img.shields.io/github/downloads/miyako/4d-plugin-office-automation/total)\n\n# 4d-plugin-office-automation\ninstruct Word and Excel to open and close documents\n\n### Examples\n\n* Open Word document\n\n```4d\n$file:=Folder(fk resources folder).file(\"テスト.docx\")\n\n$params:=New object\n$params.app:=\"word\"\n$params.path:=$file.platformPath  //if omitted, save in temporary folder (mac)\n$params.command:=\"open\"\n\n$status:=office automation ($params)\n```\n\n* Save and close Word document\n\n```4d\n$file:=Folder(fk resources folder).file(\"テスト.docx\")\n\n$params:=New object\n$params.app:=\"word\"\n$params.command:=\"close\"\n$params.name:=$file.name+$file.extension  //specify the name, not a path\n\n$status:=office automation ($params)\n```\n\n* Open Excel document\n\n```4d\n$file:=Folder(fk resources folder).file(\"テスト.xlsx\")\n\n$params:=New object\n$params.app:=\"excel\"\n$params.path:=$file.platformPath  //if omitted, save in temporary folder (mac)\n$params.command:=\"open\"\n\n$status:=office automation ($params)\n```\n\n* Save and close Excel document\n\n```4d\n$file:=Folder(fk resources folder).file(\"テスト.xlsx\")\n\n$params:=New object\n$params.app:=\"excel\"\n$params.command:=\"close\"\n$params.name:=$file.name+$file.extension  //specify the name, not a path\n\n$status:=office automation ($params)\n```\n\n### Mac\n\n* create header file from app\n\n```\nsdef Word.app \u003e word.sdef\nsdp --basename Word -fh Word.sdef Word.h\n```\n\n### Windows\n\n[How to use a type library for Office Automation from Visual C++.NET](https://docs.microsoft.com/en-us/previous-versions/office/troubleshoot/office-developer/use-type-library-for-office-from-visual-c-net)\n\n* create new MFC Application project\n* add \u003e class \u003e MFC class from Typelib\n\n* from Word 16.0\n  * Appliction (rename: `WordAppliction`)\n  * Document (rename: `WordDocument`)\n\n* from Excel 16.0\n  * Appliction (rename: `ExcelAppliction`)\n  * Workbook (rename: `ExcelWorkbook`)\n\n* release\n  * additional dependencies: `uafxcw.lib;Libcmt.lib`\n  * ignore specific default libraries: `uafxcw.lib;Libcmt.lib` \n\n* debug\n  * additional dependencies: `uafxcwd.lib;Libcmtd.lib`   \n  * ignore specific default libraries: `uafxcwd.lib;Libcmtd.lib`\n\n* other\n  * `uxtheme.lib;windowscodecs.lib` \n\nremove \n\n```c\n#import \"C:\\\\Program Files (x86)\\\\Microsoft Office\\\\Root\\\\Office16\\\\EXCEL.EXE\" no_namespace\n#import \"C:\\\\Program Files (x86)\\\\Microsoft Office\\\\Root\\\\Office16\\\\MSWORD.OLB\" no_namespace\n```\n\nremove\n\n```c\n#include \"windows.h\"\n```\n\n### Issues \n\nOn windows, `CreateDispatch` creates a new dispatch. need to search for running instances first.\n\n```c\nCOleException e;\nWordApplication wdApp;\n\nbool isAvailable = false;\n\nCLSID clsid;\nCLSIDFromProgID(L\"Word.Application\", \u0026clsid);\n\nIUnknown *pUnknown;\nHRESULT hr = GetActiveObject(clsid, NULL, (IUnknown**)\u0026pUnknown);\nif (SUCCEEDED(hr)) {\n\t//there is a running instance\n\t// Get IDispatch interface for Automation...\n\tIDispatch *pDispatch;\n\thr = pUnknown-\u003eQueryInterface(IID_IDispatch, (void **)\u0026pDispatch);\n\tif (SUCCEEDED(hr)) {\n\t\twdApp.AttachDispatch(pDispatch, TRUE);\n\t\tisAvailable = true;\n\t}\n\t}\n\telse {\n\t\tif (wdApp.CreateDispatch(L\"Word.Application\", \u0026e)) {\n\t\tisAvailable = true;\n\t}\n}\n```\n\nOn Mac, the name of a Word document is its file name.\n\nOn Windows, it is localised serial, e.g. \"文書 1\". depending on the options passed to [Open](https://docs.microsoft.com/en-us/office/vba/api/word.documents.open).\n\nin particular, `OpenAndRepair` should  be `False` to keep the original name and path.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiyako%2F4d-plugin-office-automation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiyako%2F4d-plugin-office-automation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiyako%2F4d-plugin-office-automation/lists"}