Tag: 字典

项目在字典中找不到

我在if语句中有这个条件: If myDict.Exists(Cells(d.Row, d.Column – 1)) Then 在代码中的特定步骤(在逐步完成时),立即窗口中的以下代码 MsgBox Cells(d.Row,d.Column-1) 给我的价值“1/3/2011” 在这一步, MsgBox myDict.Item("1/3/2011") 也返回一个值。 但是,我的上述条件不等同于真实。 为什么?? 我是否需要将单元格(d.Row,d.Column-1)的结果作为某种types?

有没有可能在Excel VBA中添加字典到数组?

我试图弄清楚,这是否是一个可能性方面的能力的Excel。 考虑下面的代码,我想要做什么: Dim some_text, split_text() As String Dim some_array_dict() As String 'This is the array to store the dictionaries Dim some_dict As Dictionary 'The dictionaries that I'll be storing in the array above ReDim some_array_dict(y) As String 'y is previously defined as an integer For i = 0 To y – 1 Set some_dict = […]

Excel VBA:将CompareMode设置为TextCompare与“Dictionary”时,“无效过程调用或方法”

出于某种原因,我无法将字典offONameDic的CompareMode设置为TextCompare 。 我不断收到"Invalid Procedure or Call Error" 。 我想确保用户提供的提供密钥的大小写不会影响字典将密钥识别为有效的能力,即如果密钥是“hello”,“Hello”也会被识别为密钥。 请注意,我使用VBA Excel中已安装库的列表中的Microsoft Scripting Runtime Reference 我的代码: Sub Main() '…code… Dim offONameDic As Scripting.Dictionary '…code… Set offONameDic = New Scripting.Dictionary With offONameDic .Add "Blood", "Blood" .Add "Liver", "Liver" .Add "Kidneys", "Kidneys" .Add "Kidney", "Kidneys" .Add "Spleen", "Spleen" .Add "Heart", "Heart" .Add "Lungs", "Lungs" .Add "Lung", "Lungs" .Add […]

将字典列表中的字典值写入新的列

原谅我。 我对Python很陌生。 我有一个我想要写入Excel电子表格的字典列表。 我知道每个词典将包含多less个键,每个词典将具有相同的键。 我想通过无数的字典获得列A中的键和列B中的值。 我的代码到目前为止: for each in stock_data: with open('output.csv', 'wb') as output: writer = csv.writer(output) for key, value in each.iteritems(): writer.writerow([key, value]) 但是,每次迭代都会覆盖前一个。 在此先感谢您的帮助。 编辑:在那些花时间来回答的帮助下,我结束了这个(词典的价值是元组): with open('output.csv', 'wb') as output: fieldnames = ['Volume', 'Symbol', 'Adj_Close', 'High', 'Low', 'Date', 'Close', 'Open'] writer = csv.DictWriter(output, fieldnames=fieldnames) writer.writeheader() writer = csv.writer(output) for each in stock_data: […]

Excel Power Map – 如何突出整个国家

使用Excel 2013的电力地图,我想弄清楚如何突出整个国家。 目前,当我有一个国家的名字,它只是在该国的中间点。 我想突出整个国家。 有人可能知道如何做到这一点? 我试图达到的一个例子可以看到这个video2m55s: https : //www.youtube.com/watch?v= nFEq3m2RABQ&list = WL&index =5

Python将字典输出到excel文件

我有一个txt格式的字典 – 这是文件的一部分(它包含6000个键:值: {'YAL008W': 25, 'YBR255W': 50, 'YGR164W': 37, 'YGR131W': 40, 'YNL003C': 11, 'YBR135W': 2, 'YBR160W': 6, 'YJL082W': 79, 'YJL142C': 4, 'YPL191C': 38, 'YGL215W': 31, 'YKL074C': 33, 'YJL077C': 67, 'YKL096W-A': 22, 'YIL124W': 60, 'YLR364C-A': 2, 'YPL039W': 58, 'YNL170W': 16, 'YGL141W': 62, 'YJL179W': 15, 'YDR316W-A': 13, 'YDR316W-B': 139, 'YKL083W': 25, 'YOR009W': 25, 'YKL029C': 395, 'YPL166W': 31, […]

使用openpyxl使用电子表格的行创build对象列表

我在Excel中有一个表格,如下所示: ID Address Type 1 2 John Avenue family 2 3 John Avenue single woman 3 4 John Avenue single man 4 5 John Avenue mixed couple 5 6 John Avenue youth 6 7 John Avenue family 7 8 John Avenue single woman 我想读取表中的每一行(不包括标题),并将每行转换为“Person”类的实例。 为了做到这一点,我试图把每一行读成一个字典,以“ID”作为关键。 我正在使用“openpyxl”从Excel文件中读取。 一旦我能够将Excel文件中的数据存储到字典中,我计划创build“Person”类的实例 – 尽pipe我不确定这是否是最好的方法。 这是我到目前为止的代码: from openpyxl import load_workbook class […]

excel vba词典vlookup

我的代码需要超过一个小时才能完成3500行,但我需要为超过40000行数据工作。 我正在寻找替代我的代码,通过使用字典,在感兴趣的上下文中提高性能。 任何人都可以帮我吗? Sub StripRow2Node() 'Read the Strip Design table With Sheets("Design-Moment") Sheets("Design-Moment").Activate LastR1 = .Range("B" & Cells.Rows.Count).End(xlUp).Row DM_arr = .Range(Cells(1, 1), Cells(LastR1, 7)) 'Col 1 to Col 7 DM_count = UBound(DM_arr, 1) End With 'Read the x and y coordinations and thickness of a node in node design With Sheets("Design-Shear") Sheets("Design-Shear").Activate LastR2 = .Range("B" […]

将数据从一个Excel文件转换成一个Python字典

我试图将数据从Excel文件转换为Python字典。 我的Excel文件有两列和许多行。 Name Age Steve 11 Mike 10 John 11 我怎样才能把这个添加到字典与年龄作为关键和名称作为价值? 而且,如果很多名字都有相同的年龄,他们应该都是一个数组。 例如: {'11':['Steve','John'],'10':['Mike']} 我到目前为止写的是: import xlsxwriter import openpyxl wb = openpyxl.load_workbook('demo.xlsx') sheet = wb.get_sheet_by_name('Sheet1') #print sheet.cell(row=2, column=2).value age_and_names = {} for i in range(1,11): age = sheet.cell(row=i, column=2).value name = sheet.cell(row=i, column=1).value #Problem seems to be in this general area if not age in […]

在新工作表中打印字典键

这里是我的macros工作的数据的一个例子。 下面的代码使用一个字典对象计算button然后AOI项,然后打印到同一工作表上的其他列的计数: Dim dBT As Object 'global dictionary Sub buttonpresscount() 'constants for column positions Const COL_BLOCK As Long = 1 Const COL_TRIAL As Long = 2 Const COL_ACT As Long = 7 Const COL_AOI As Long = 8 Dim rng As Range, lastrow As Long, sht As Worksheet Dim d, r As Long, k, resBT() […]