我有一个程序,可以在现有电子表格文件中创建一个新工作表,并对该工作表应用保护,以保护某些标头和元数据免于更改,同时允许编辑“数据”单元格。
工作表中的所有单元格仍应能够进行格式化(已实现)。同样,仅“数据”行应能够删除(第7行及以后)。尝试了以下代码:
worksheet.Protection.IsProtected = true;
// this works
worksheet.AllowFormatColumns = true;
worksheet.AllowFormatCells = true;
// this doesn't allow any rows to be deleted.
worksheet.AllowDeleteRows = true;
worksheet.AllowDeleteColumns = true;
int row = 7;
while (spreadsheetCellRangeHasData(worksheet.Cells[row,1])
{
// this is a data row, so unlock it
// it works, can edit text in cells in row 7 and beyond which have data in them. Still, cannot delete them.
worksheet.Cells[row,1].Style.Locked = false;
row++;
}
允许删除代码也放置在while
循环之后,无济于事。理想情况下,如果第一列不为null,则应该只允许删除从7开始的行。