通过 C# 编程仅在 Excel 单元格中显示数字

发布于 2024-08-07 17:43:05 字数 153 浏览 3 评论 0原文

我从 .NET C# 应用程序生成一些 Excel 文件。我使用 PIA 2002。

我可以使用密码保护、冻结窗格、更改单元格的颜色......这是我做不到的一件事。我想允许一个特定的范围,用户只能输入一个数字......

我该怎么做?

谢谢,

I generate some Excel file from an .NET C# application. I use PIA 2002.

I can password protect, do a freeze pane, change the color of the cells .... one thing I can't do. I'd like to allow for a specific range, the use can enter ONLY a number.....

How can I do this ?

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黑凤梨 2024-08-14 17:43:05

我不确定 C# 提供哪些控件,但 Excel 有一个内置功能,您可以访问它。数据验证功能允许您控制单元格中允许输入的内容。我会打开 Excel 并使用这些选项,然后看看是否可以在 C# 中引用。我想如果你能做你列出的所有其他事情,你就能做到。

您需要根据您的要求选择允许“整数”或“小数”。

I'm not sure of the controls available from C#, but Excel has a feature built in that would work in you can access it. The Data Validation feature allows you to control what entry is allowed in a cell. I would open Excel and play with the options, then see if you can reference in C#. I imagine you can if you can do all the other things you listed.

You'll want to choose to allow either 'whole number' or 'decimal' depending on your requirements.

若水般的淡然安静女子 2024-08-14 17:43:05

不幸的是,无法仅在整个工作表上为每个单元格分配事件。您唯一能做的就是不断检查该范围中是否只有数字值。这相对容易,因为您可以一次将整个范围的值放入 double[][]

Unfortunately there is no way to assign events per cells only on the whole worksheet. The only thing you can do is constantly check that range for values that are only numbers. This is relatively easy since you can get the values of the whole range in one shot into a double[][]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文