更新行 Excel
PDF4me 更新行 是一个 REST 写入端点 JSON 将数据插入到现有行中 Excel 工作簿。 POST 将 .xlsx 文件作为 Base64 到 office/ApiV2Excel/ExcelUpdateRows 将您的数据 jsonInput按以下方式选择目标行 Excel 通过表名或从 1 开始的坐标,解码更新后的工作簿。 JSON 响应。默认情况下,数值和日期转换是自动的。
需要一本练习册和 JSON 将对象数组中的值写入现有行:刷新价目表中的价格、更正报表中的记录、同步来自您的字段 CRM您可以选择两种目标定位模式之一,或通过命名方式,将数据发送到指定位置。 Excel 表格或确切的行和列坐标。响应是 JSON 更新后的工作簿 Base64 内容。
验证您的身份 API 要求
每一个 PDF4me REST 通话必须包含您的 API 关键在于 Authorization 请求头设置为基本身份验证。请从开发者控制面板获取或轮换您的密钥。
端点
办公室/ApiV2Excel/ExcelUpdateRows您不容错过的重要事实
json输入直接发送原始数组是导致此端点返回 400 错误的最常见原因。请先序列化,然后再嵌入。tableName 切换到桌面模式 excelRowNumber空的表示坐标模式 insertFromRow/insertFromColumn所有位置均从 1 开始。fileName, success, 和 错误信息请先解码再保存;原始响应不是有效的 .xlsx 文件。HTTP 设置
方法: POST
URL: https://api.pdf4me.com/office/ApiV2Excel/ExcelUpdateRows
内容类型: application/json
Authorization: 基本 <您的 PDF4me API 键>
回答是 JSON检查 success 然后,举旗。 Base64-解码返回的工作簿内容并将其保存 .xlsx 扩大。
我应该使用表格模式还是坐标模式?
这两种模式适用于不同的工作表布局,选择错误的一种通常是导致更新内容出现在错误单元格中的原因。
| 表格模式与坐标模式 | 表格模式 | 坐标模式 |
|---|---|---|
| 如何选择它 | 放 tableName 一个命名者 Excel 桌子 | 离开 tableName 空的 |
| 数据最终落在哪里 | 排 excelRowNumber 表格内部(从 1 开始) | 从 insertFromRow/insertFromColumn (从 1 开始,所以 1/1 是 A1) |
| 列匹配 | JSON 属性名称对应于表列标题 | 数值从起始列的左到右写入 |
| 能够经受住布局变化 | 是的,如果表格移动,更新也会随之进行。 | 不,坐标是固定位置。 |
| 最适合 | 结构化工作表,包含真实数据 Excel 表格 | 普通范围和临时表格 |
API 身体场
| 范围 | 必需的 | 类型 | 它的作用 | 例子 |
|---|---|---|---|---|
document | Required | object | Document reference carrying Name, the Excel filename with its extension. | { "Name": "data.xlsx" } |
docContent | Required | string | Base64-encoded bytes of the workbook to update. | UEsDBBQABgAIAAAA... |
updateRowsToExcelAction | Required | object | Action configuration object holding jsonInput and all targeting options below. | { "jsonInput": "..." } |
jsonInput | Required | string | Inside the action object. A STRING containing an escaped JSON array of objects; property names become column targets in table mode. | "[{\"Name\":\"John\",\"Age\":31}]" |
worksheetName | Optional | string | Inside the action object. Target worksheet; defaults to the first sheet when omitted. | Sheet1 |
tableName | Conditional | string | Inside the action object. Names the Excel table for table mode. Empty or omitted switches the action to coordinate mode. | SalesTable |
excelRowNumber | Conditional | number | Inside the action object. Table mode only: the 1-based row position within the table to update. | 5 |
insertFromRow | Conditional | number | Inside the action object. Coordinate mode only: the 1-based worksheet row where writing starts. | 10 |
insertFromColumn | Conditional | number | Inside the action object. Coordinate mode only: the 1-based worksheet column where writing starts. | 1 |
convertNumericAndDate | Optional | boolean | Inside the action object. true (default) writes numeric-looking and date-looking values as real Excel numbers and dates instead of text. | true |
cultureName | Optional | string | Inside the action object. Culture used to parse dates and numbers, for example en-US or de-DE. Pair with convertNumericAndDate. | en-US |
示例有效载荷
表格模式:更新指定表的第 5 行
{
"document": { "Name": "sales.xlsx" },
"docContent": "UEsDBBQABgAIAAAA...",
"updateRowsToExcelAction": {
"jsonInput": "[{\"Region\":\"EMEA\",\"Revenue\":125000}]",
"worksheetName": "Q3",
"tableName": "SalesTable",
"excelRowNumber": 5
}
}
坐标模式:从单元格 A10 开始写入
{
"document": { "Name": "data.xlsx" },
"docContent": "UEsDBBQABgAIAAAA...",
"updateRowsToExcelAction": {
"jsonInput": "[{\"Name\":\"John\",\"Age\":31},{\"Name\":\"Ana\",\"Age\":28}]",
"insertFromRow": 10,
"insertFromColumn": 1,
"convertNumericAndDate": true,
"cultureName": "en-US"
}
}
邮递员收款小贴士
curl 示例
curl -X POST https://api.pdf4me.com/office/ApiV2Excel/ExcelUpdateRows \
-H "Content-Type: application/json" \
-H "Authorization: Basic YOUR_API_KEY" \
-d '{
"document": { "Name": "data.xlsx" },
"docContent": "'"$(base64 -w 0 data.xlsx)"'",
"updateRowsToExcelAction": {
"jsonInput": "[{\"Name\":\"John\",\"Age\":31}]",
"insertFromRow": 10,
"insertFromColumn": 1
}
}' \
--output response.json
什么 API 返回?
A JSON 结果包含更新后的工作簿 Base64。
| 场地 | 类型 | 它包含什么 |
|---|---|---|
document | String (Base64) | The updated workbook content. Decode to bytes and save with an .xlsx extension. |
fileName | String | Output filename for the updated workbook. |
success | Boolean | true when the update succeeded. Check this before decoding content. |
errorMessage | String | Populated when success is false: malformed jsonInput, a missing table or worksheet, or invalid Base64. |
输出保持标准 办公室开放 XML 工作簿,因此更新单元格之外的公式、格式和工作表均不受影响。
代码示例
Excel 办公终端尚未包含在按百分比计费的范围内。language 示例文件夹;示例存储库包含每个请求使用的请求模式。 PDF4me 端点系列:
常问问题
为什么要更新 Excel 通过行 API 而不是手动操作?
手动操作需要打开每个工作簿,找到相应的行,重新输入值,然后保存:这种方法可行一次,但对于每晚从系统同步数据的操作来说就行不通了。 CRM 或数据库。 API 对每个文件执行与一次确定性请求相同的编辑操作,并保留 Excel 表格 完好无损,而且永远不需要 Excel 已安装在服务器上。输出为标准格式。 办公室开放 XML 工作簿已准备好进行下一步流程。