c# - 如何使用 smartsheet c# sdk 更新链接附件?
问题描述
我有一个带有一堆链接附件的智能表。我想用不同的子字符串替换链接的开头。我是 smartsheet 的新手,找不到太多示例代码。
表设置,
SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();
PaginatedResult<Sheet> sheets = smartsheet.SheetResources.ListSheets(
null, // IEnumerable<SheetInclusion> includes
null, // PaginationParameters
null // Nullable<DateTime> modifiedSince = null
);
long sheetId = (long)sheets.Data[1].Id; //get first sheet's ID
//get sheet associated with sheetId
Sheet sheet = smartsheet.SheetResources.GetSheet(sheetId, null, null, null, null, null, null, null);
在这里,我正在尝试创建包含必须更改的链接的行列表,
List<Row> rowsToUpdate = new List<Row>();
foreach (var row in sheet.Rows)
{
Row rowToUpdate = null;
var cellsToUpdate = new List<Cell>();
var at = row.Attachments;
string toReplace = "http://blahblah/blah";
string newValue = "https://hello/";
foreach(var attachment in row.Attachments)
{
var url = attachment.Url;
var id = attachment.Id;
if (url!=null && url.Contains(toReplace)){
var newUrl = url.Replace(toReplace, newValue);
}
}
//create new cell that will contain updated links
var cellToUpdate = new Cell {
ColumnId = , //is it possible to get Attachments column Id?
Value = //add updated links here?
};
cellsToUpdate.Add(cellToUpdate);
//this will be added to the list rowsToUpdate
rowToUpdate = new Row {
Id = row.Id,
Cells = cellsToUpdate
};
}
smartsheet.SheetResources.RowResources.UpdateRows(sheet.Id.Value, rowsToUpdate);
我尝试获取附件列 ID,但此方法不起作用,因为我认为它是主列(?)
var columns = smartsheet.SheetResources.ColumnResources.ListColumns(sheetId, null, null).Data;
var attachmentCol = columns[0].Title;
谢谢您的帮助。
解决方案
行上的附件不指定为列,而是单独的行属性。当您打电话时,GetSheet
您需要在回复中包含附件:
Sheet sheet = smartsheet.SheetResources.GetSheet(sheetId, new List<SheetLevelInclusion> { SheetLevelInclusion.ATTACHMENTS },
null, null, null, null, null, null);
要更新 URL,您可能必须删除附件:
smartsheet.SheetResources.AttachmentResources.DeleteAttachment(
9283173393803140, // long sheetId
7169782752536452 // long attachmentId
);
然后重新添加修改后的附件:
Attachment attachmentSpecification = new Attachment
{
Url = "http://www.google.com",
AttachmentType = AttachmentType.LINK,
Name = "Search Engine"
};
// Attach URL to row
Attachment updatedAttachment = smartsheet.SheetResources.RowResources.AttachmentResources.AttachUrl(
9283173393803140, // long sheetId
0123456789012345, // long rowId
attachmentSpecification
);
推荐阅读
- angular6 - 应用溢出:隐藏到 .mat-tab-body-content
- android - 使用 ConstraintLayout 的简单但复杂的布局
- salesforce - 无法从 SOQL 查询中的 createdDate 中提取年份
- marklogic - marklogic 中的 Cts 和 Xmdp 函数
- python - 如何摆脱python中的多个嵌套循环
- sql - 我可以在 SQL 的 IIF 中执行存储过程吗?
- sql-server - SQL Always On 辅助副本限制
- javascript - 有没有办法使用另一个页面中的对象?
- angular - Angular数据表有没有办法在用户在搜索按钮中输入相同的内容之前不显示数据
- python - 如何使用 PyGithub 在 Github 中创建私有存储库