跳到主要内容

更新行 Excel

PDF4me 更新行 是一个 REST 写入端点 JSON 将数据插入到现有行中 Excel 工作簿。 POST 将 .xlsx 文件作为 Base64office/ApiV2Excel/ExcelUpdateRows 将您的数据 jsonInput按以下方式选择目标行 Excel 通过表名或从 1 开始的坐标,解码更新后的工作簿。 JSON 响应。默认情况下,数值和日期转换是自动的。

此端点的作用

需要一本练习册和 JSON 将对象数组中的值写入现有行:刷新价目表中的价格、更正报表中的记录、同步来自您的字段 CRM您可以选择两种目标定位模式之一,或通过命名方式,将数据发送到指定位置。 Excel 表格或确切的行和列坐标。响应是 JSON 更新后的工作簿 Base64 内容。

相关博客文章
目前尚无关于此功能的博客文章——敬请期待。
在此期间,您可以浏览 PDF4me 博客,查看适用于各平台的教程和工作流程。
访问博客

验证您的身份 API 要求

每一个 PDF4me REST 通话必须包含您的 API 关键在于 Authorization 请求头设置为基本身份验证。请从开发者控制面板获取或轮换您的密钥。

端点

POST办公室/ApiV2Excel/ExcelUpdateRows

您不容错过的重要事实

jsonInput 是一个字符串,而不是一个 JSON 大批
更新数据以转义字符串的形式传输。 JSON 字符串内部 json输入直接发送原始数组是导致此端点返回 400 错误的最常见原因。请先序列化,然后再嵌入。
两种目标定位模式,由表名选择
一个非空的 tableName 切换到桌面模式 excelRowNumber空的表示坐标模式 insertFromRow/insertFromColumn所有位置均从 1 开始。
回答是 Base64 JSON不是文件
更新后的工作簿以以下形式返回: Base64 字符串内部 JSON 身体 fileNamesuccess, 和 错误信息请先解码再保存;原始响应不是有效的 .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 身体场

范围必需的类型它的作用例子
documentRequiredobjectDocument reference carrying Name, the Excel filename with its extension.{ "Name": "data.xlsx" }
docContentRequiredstringBase64-encoded bytes of the workbook to update.UEsDBBQABgAIAAAA...
updateRowsToExcelActionRequiredobjectAction configuration object holding jsonInput and all targeting options below.{ "jsonInput": "..." }
jsonInputRequiredstringInside the action object. A STRING containing an escaped JSON array of objects; property names become column targets in table mode."[{\"Name\":\"John\",\"Age\":31}]"
worksheetNameOptionalstringInside the action object. Target worksheet; defaults to the first sheet when omitted.Sheet1
tableNameConditionalstringInside the action object. Names the Excel table for table mode. Empty or omitted switches the action to coordinate mode.SalesTable
excelRowNumberConditionalnumberInside the action object. Table mode only: the 1-based row position within the table to update.5
insertFromRowConditionalnumberInside the action object. Coordinate mode only: the 1-based worksheet row where writing starts.10
insertFromColumnConditionalnumberInside the action object. Coordinate mode only: the 1-based worksheet column where writing starts.1
convertNumericAndDateOptionalbooleanInside the action object. true (default) writes numeric-looking and date-looking values as real Excel numbers and dates instead of text.true
cultureNameOptionalstringInside 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"
}
}

邮递员收款小贴士

Headers
Content-Type: application/json + Authorization: Basic <apiKey>.
Body
raw JSON. jsonInput must be a string: escape the inner quotes or use your HTTP library to serialize the array first, then assign it as a string.
Targeting
tableName set = table mode with excelRowNumber. tableName empty = coordinate mode with insertFromRow/insertFromColumn. Both are 1-based.
Response
JSON with a success flag and Base64 workbook content. Decode the document field before saving as .xlsx.

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

场地类型它包含什么
documentString (Base64)The updated workbook content. Decode to bytes and save with an .xlsx extension.
fileNameStringOutput filename for the updated workbook.
successBooleantrue when the update succeeded. Check this before decoding content.
errorMessageStringPopulated when success is false: malformed jsonInput, a missing table or worksheet, or invalid Base64.

输出保持标准 办公室开放 XML 工作簿,因此更新单元格之外的公式、格式和工作表均不受影响。

代码示例

Excel 办公终端尚未包含在按百分比计费的范围内。language 示例文件夹;示例存储库包含每个请求使用的请求模式。 PDF4me 端点系列:

常问问题

Why does the API reject my jsonInput with a 400 error?+
jsonInput is a string field that contains JSON, so the inner quotes must be escaped. Sending a raw JSON array instead of a string-encoded one is the most common cause of a 400 Bad Request on this endpoint.
Should I use table mode or coordinate mode?+
Use table mode (tableName plus excelRowNumber) when the worksheet has a named Excel table: the update follows the table even if it moves. Use coordinate mode (insertFromRow and insertFromColumn, tableName empty) for plain ranges at fixed positions.
Are the row and column numbers 0-based or 1-based?+
1-based. insertFromRow 1 and insertFromColumn 1 address cell A1, and excelRowNumber 1 is the first data row of the table. This differs from some other PDF4me Excel actions where worksheet indexes are 0-based.
Is the response the Excel file itself?+
No. The API returns JSON containing the updated workbook as a Base64 string plus fileName, success, and errorMessage fields. Decode the document field to bytes before saving as .xlsx.
How are numbers and dates handled?+
convertNumericAndDate defaults to true, so values that look like numbers or dates are written as real Excel numbers and dates rather than text. Pair it with cultureName so formats like 31.12.2026 or 12/31/2026 parse correctly.
What is the difference between Update Rows and Add Rows?+
Update Rows overwrites values in rows that already exist at the targeted position. Add Rows appends or inserts new rows. If you point Update Rows at empty cells it simply writes the values there; it does not shift existing data down.
Can I update rows in a protected workbook?+
No. Protection blocks editing. Chain the Unlock Excel action first with the correct password, run the update, then re-apply protection with Secure Excel Document if needed.

为什么要更新 Excel 通过行 API 而不是手动操作?

手动操作需要打开每个工作簿,找到相应的行,重新输入值,然后保存:这种方法可行一次,但对于每晚从系统同步数据的操作来说就行不通了。 CRM 或数据库。 API 对每个文件执行与一次确定性请求相同的编辑操作,并保留 Excel 表格 完好无损,而且永远不需要 Excel 已安装在服务器上。输出为标准格式。 办公室开放 XML 工作簿已准备好进行下一步流程。

相关行动

在其他平台上执行相同的任务

获取帮助