Code Generation Standards
Must comply
- Only use
var to declare variables
- Do not use arrow functions
=>
- Do not use
let、const、class, template literals
- The last line of the code must return a string result
- The total code length must not exceed 3000 characters
Security Standards
- Wrap all document operations in try/catch
- Check object existence before operations
- Do not delete content outside the selection (unless explicitly required)
- Confirm the paragraph count before bulk modifications
- Do not modify document properties (author, date, etc.) unless explicitly required
Return Value Standards
// 好的返回值
return "已替换选区文本(原 120 字 → 新 85 字)";
return "已插入 3 行 × 4 列表格";
return "已将全文 28 个段落的字体设为微软雅黑 12pt";
// 差的返回值
return "done";
return undefined; // 忘记返回
Error Handling
var doc = Application.ActiveDocument;
if (!doc) return "无活动文档,请先打开一个文档";
var sel = Application.Selection;
if (!sel.Text || sel.Text.trim().length === 0) {
return "请先选中要操作的文本";
}
try {
// ... 操作
return "操作成功";
} catch (e) {
return "操作失败: " + (e.message || String(e));
}