- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Summary
Objective
Application
,
Workbook
,
Worksheet
和
Range
类/接口(interface),同时仅公开每个对象最常用的对象属性。
Usage example
Dim file as String = "C:\Temp\WriteTest.xls"
Using mgr As ISpreadsheetManager = New SpreadsheetManager()
Dim wb as IWorkbook = mgr.CreateWorkbook()
wb.Sheets("Sheet1").Cells("A1").Value = 3.1415926
wb.SaveAs(file)
End Using
Dim file as String = "C:\Temp\WriteTest.xls"
Using mgr As ISpreadsheetManager = New SpreadsheetManager()
Dim wb as IWorkbook = mgr.OpenWorkbook(file)
// Working with workbook here...
End Using
Discussion
Range
初始化其单元格。可以表示一个或多个单元格的对象。 Thoughts
Range
在需要的时候; ICell
提供最常用的属性界面; Range
工作表的单元格从其初始化。 Range.Value
属性是使用 Interop 与基础 Excel 应用程序实例的最快交互。
ReadonlyOnlyDictionary(Of String, ICell)
不立即包装
Range
实例的单元格名称接口(interface),这样我就可以简单地生成行和列索引以及单元格的名称来索引我的字典,然后分配
Cell.NativeCell
仅当想要访问或格式化特定单元格或单元格范围时才具有属性。
Worksheet
中生成的列索引获得的单元格名称进行索引。类构造函数。然后,当一个人会这样做:
Using mgr As ISpreadsheetManager = New SpreadsheetManager()
Dim wb As IWorkbook = mgr.CreateWorkbook()
wb.Sheet(1).Cells("A1").Value = 3.1415926 // #1:
End Using
Cell
中的索引类将给定值写入特定单元格,这比直接使用它的名称对
Range
更快。 .
Questions and Concerns
UsedRange.get_Value()
时或
Cells.get_Value()
,这将返回 Object(,) 数组。
Object(,)
感到满意吗?单元格的数组,而无法以某种方式对其进行格式化?
Object(,)
时获得最佳性能数组,同时保持 Cell 实例可以表示或包装单个单元格 Range 的可能性?
Thanks to any of you who takes the time to read my post and my sincerest thanks to those who answer.
最佳答案
使用的体系结构经过了我命名为 CellCollection
的对象类。 .这是它的作用:
基于这些假设:
Given that an Excel worksheet has 256 columns and 65536 lines;
Given that 16,777,216 (256 * 65536) cells needed to be instantiated at a time;
Given that the most common use of a worksheet takes less then 1,000 lines and less than 100 columns;
Given that I needed it to be able to refer to the cells with their addresses ("A1"); and
Given that it is benchmarked that accessing all the values at once and load them into a
object[,]
in memory as being the fastest way to work with an underlying Excel worksheet,*
CellCollection
我的
IWorksheet
内的属性(property)接口(interface)初始化并在实例化时为空,现有工作簿除外。因此,在打开工作簿时,我验证了
NativeSheet.UsedRange
为空或返回 null(在 Visual Basic 中为空),否则,我已经在内存中获得了使用过的“ native 单元”,因此只需将它们添加到我的内部
CellCollection
字典,同时用它们各自的地址索引它们。
public class Sheet : ISheet {
public Worksheet(Microsoft.Office.Interop.Excel.Worksheet nativeSheet) {
NativeSheet = nativeSheet;
Cells = new CellCollection(this);
}
public Microsoft.Office.Interop.Excel.Worksheet NativeSheet { get; private set; }
public CellCollection Cells { get; private set; }
}
public sealed class CellCollection {
private IDictionary<string, ICell> _cells;
private ReadOnlyDictionary<string, ICell> _readonlyCells;
public CellCollection(ISheet sheet) {
_cells = new Dictionary<string, ICell>();
_readonlyCells = new ReadonlyDictionary<string, ICell>(_cells);
Sheet = sheet;
}
public readonly ReadOnlyDictionary<string, ICell> Cells(string addresses) {
get {
if (string.IsNullOrEmpty(addresses) || 0 = address.Trim().Length)
throw new ArgumentNullException("addresses");
if (!Regex.IsMatch(addresses, "(([A-Za-z]{1,2,3}[0-9]*)[:,]*)"))
throw new FormatException("addresses");
foreach(string address in addresses.Split(",") {
Microsoft.Office.Interop.Excel.Range range = Sheet.NativeSheet.Range(address)
foreach(Microsoft.Office.Interop.Excel.Range cell in range) {
ICell c = null;
if (!_cells.TryGetValue(cell.Address(false, false), c)) {
c = new Cell(cell);
_cells.Add(c.Name, c);
}
}
}
return _readonlyCells;
}
}
public readonly ISheet Sheet { get; private set; }
}
显然,这是第一次尝试,到目前为止它工作得很好,具有超过可接受的性能。不过谦虚地说,我觉得它可以使用一些优化,虽然我现在会这样使用它,如果需要,以后再优化它。
IEnumerable
,
IEnumerable<T>
,
ICollection
,
ICollection<T>
等,因此可以分别将其视为真正的 .NET 集合。
关于.net - 在允许我实例化工作表的单元格的同时,使用什么架构来解决这个 SystemOutOfMemoryException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5183833/
我最近一直在学习 Clojure。 Clojure 世界中是否有类似 Scala 的工作表这样的东西,我可以在其中放入任何代码并在保存后立即对其进行评估?或者也许 Clojure 有类似的解决方案?
有人可以帮我吗?我想知道如何过滤工作表中的多个选项卡(C1-C19)。这是我所做的: 我创建了一张表格,将所有回复存储在我的谷歌表单(事件注册表单)中。每个参与者将收到一个坦克编号,每个坦克编号根据其
这就是我将打开的面板显示为 float 窗口的方式。 有人可以帮我将面板作为工作表运行吗?窗口对象是mWindow。我使用的许多标准代码都已被折旧。 NSOpenPanel *openPanel =
当您仅键入 worksheets() 时,默认范围 ActiveWorkbook 或 ThisWorkbook 是什么?对于那些不了解这些区别的人来说,它们非常重要,尤其是在 Excel 2013 中
我有一个带有一些图表的 HTML 页面。我想要做的是编写一个加载 javascript 函数,它将从 excel 表中读取值,将它们存储在变量中并在 html 页面上使用它们。我的问题是是否有任何 j
我需要将参数 callFrom 传递给 SwiftUI 中的工作表。 奇怪的是,该参数在第一次调用时没有使用,但对以下调用有效。 import SwiftUI struct ContentView:
我试着 var tempSheet = wrksheets[sheetName] as Worksheet; 在哪里 wrksheets是类型表 sheetName 是“带空格的工作表名称” 如果
该函数用作“ Assets 类别分配”引擎(在参数范围内具有约束)并在数组的每一行上模拟投资组合模型。我尝试使用四种方法将数组发布到工作表上,但每种方法都失败了。 对于 Assets A、B、C、D
目前,我的 excel 文件有两张表,一张名为“English”,一张名为“French”。 我以编程方式打开我的工作簿并编辑我的英文表,没有任何问题。当我打开第二张工作表时,出现以下错误: The
我添加了一个 VBA 表单 userform和一个模块 Module1在 Excel 中打开 Microsoft VBA 编辑器 (Alt+F11)。 现在,每当我打开任何其他 Excel 时,按 A
在单个 Excel 工作簿中,我想选择各种工作表来运行 VBA 子例程。我找到了显示如何遍历选定工作表的代码,它使用“MsgBox sh.Name”;但是,当我将代码放入其中时,它只会影响选择的最后一
我想知道是否有一个函数可以在 Excel 中加载特定于 Python 的工作表,例如,如果我有 34 张工作表只加载前 25 张工作表。通过以下行,我加载了所有工作表。 xlsx=pd.ExcelFi
我有一个名为“A”、“B”、“C”等的工作表的 xlsx。我需要形成一个名称为“A”、“B”、“C”的表作为第一列,以及来自的一些数据每个工作表中与第二列相同的单元格。例如,这可能看起来像: S
我有一张用密码保护的工作表。当我使用 VBA 更改该表上的任何内容时,我会像这样取消保护: Private Sub Worksheet_Change(ByVal target As Range)
我想将 Excel 文档插入 Excel 工作表。我可以通过以下步骤手动执行此操作; 插入/文本/对象/从文件创建(勾选显示为图标)/浏览。 然后我选择文件并插入文档。 我想通过宏来做到这一点。 (录
是否可以创建 批处理文件那将执行以下操作? 重命名 Excel 文件中的单个工作表(不是 Excel 工作簿/文件本身) 将简单格式应用于 Excel 文件 - 例如,将字体和字体大小应用于整个工作簿
Private Sub CommandButton1_Click() Dim ws As Worksheet With Application.FileDialog(msoFileDialog
我想知道是否可以在不复制该工作表的情况下引用另一本工作簿中的 Excel 工作表? 情况:我有一些非常大的工作表,其中充满了各种数据,但我不想在我的工作簿中保留它们的副本,因为虽然每个工作簿都使用相同
我有这个 Python 字典,我想将这个数据写入 Excel 文件。 注意:有很多类别,每个类别有很多汽车(为简单起见,我使用了 2 个类别) data = {"Category": {"Diesel
我有一个 excel 工作簿,在工作簿中我有 2 张名为 Front Page 和 Drafting 的工作表。起草工作表引用了首页工作表中的一些值。这只是一个基本的引用 我有像这样的公式:='Fro
我是一名优秀的程序员,十分优秀!