使用错误检查选项

错误类型

表示公式无法返回结果的错误,比如通过零进行数字除法,需要立即关注并在单元格中显示错误值。单击绿色三角形显示一个感叹号,单击打开一个选项列表。

可以通过选项解决错误,也可以选择忽略错误。忽略错误意味着该错误在后续错误检查中不再显示。

Aspose.Cells for Python via .NET 提供了错误检查功能。ErrorCheckOption 类管理不同类型的错误检测,例如数字以文本存储、公式计算错误以及验证错误。使用 ErrorCheckType 枚举设置所需的错误检测类型。

作为文本存储的数字

有时,数字可能被格式化并作为文本存储在单元格中。这可能会导致计算出现问题或产生令人困惑的排序顺序。格式为文本的数字在单元格中是左对齐而不是右对齐的。如果应执行单元格上的公式未返回值,则检查公式引用的单元格中的对齐方式 - 可能是其中一些或全部的单元格被格式为文本。

可以使用错误检查选项快速将作为文本存储的数字转换为实际数字。在Microsoft Excel 2003中:

  1. 在“工具”菜单上,单击“选项”。
  2. 选择错误检查标签页。默认勾选“数字存储为文本”选项。
  3. 取消其选中状态。

以下示例代码演示了如何使用 Aspose.Cells for Python via .NET API 禁用工作表中“数字存储为文本”的错误检测选项。

from aspose.cells import CellArea, ErrorCheckType, Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create a workbook and opening a template spreadsheet
workbook = Workbook(dataDir + "Book1.xlsx")
# Get the first worksheet
sheet = workbook.worksheets[0]
# Instantiate the error checking options
opts = sheet.error_check_options
index = opts.add()
opt = opts[index]
# Disable the numbers stored as text option
opt.set_error_check(ErrorCheckType.TEXT_NUMBER, False)
# Set the range
opt.add_range(CellArea.create_cell_area(0, 0, 1000, 50))
dataDir = dataDir + "out_test.out.xlsx"
# Save the Excel file
workbook.save(dataDir)