64位Excel VBA有一个讨厌的习惯,即在将数组分配给范围时将数组日期转换为数字.另一方面,32位VBA保留日期格式.
以下是一些示例代码,用于演示不同的日期处理:
Sub test()
Dim arr(0 to 1) As Variant
arr(0) = "Text"
arr(1) = #9/12/2007#
ActiveSheet.Range("A1:B1") = arr
End Sub
Run Code Online (Sandbox Code Playgroud)
(请注意,如果使用单个日期值,则不会在64位Excel中转换日期;必须具有第一个文本值)
在32位Excel中运行时,输出为 Text, 9/12/2007
在64位Excel中运行时,输出为 Text, 39337
就好像64位VBA仅对所有范围对象使用Value2属性.
如何在不编写处理所有数组写入的函数的情况下使64位VBA表现得像32位VBA?
只是为了阻止可能的善意回应:我知道这些细胞之间的基本公式保持不变.但是,32位Excel会自动将正确的单元格设置为日期格式,从而大大简化了我的代码.
我有文件名"abc枚.xlsx",包含某种非ASCII字符编码,我想删除所有非ASCII字符,将其重命名为"abc.xlsx".
这是我尝试过的:
import os
import string
os.chdir(src_dir) #src_dir is a path to my directory that contains the odd file
for file_name in os.listdir():
new_file_name = ''.join(c for c in file_name if c in string.printable)
os.rename(file_name, new_file_name)
Run Code Online (Sandbox Code Playgroud)
以下错误导致os.rename():
builtins.WindowsError: (2, 'The system cannot find the file specified')
Run Code Online (Sandbox Code Playgroud)
这是在Windows系统上,sys.getfilesystemencoding()给我mbcs,如果这有帮助.
我该怎么做才能绕过这个错误并允许我更改文件名?
SQLAlchemy v1.0.6
cx_Oracle v5.2
Run Code Online (Sandbox Code Playgroud)
我们在生产代码上遇到了一段时间的问题,最后将其缩小到SQLAlchemy的数据.
多次运行相同的查询有时会返回空结果.在某些情况下,我们可以在每次执行代码时返回一个空结果.尽管事实上数据库中的数据根本没有改变,并且直接在cx_Oracle上运行的同一查询的纯SQL版本总是返回正确的结果.
这是SQLAlchemy的声明代码:
class Database:
def __init__(self, service_name, database, username, password):
"""
service_name (str): The service name as defined in tnsnames.ora.
database (str): The database within the chosen service.
"""
self.engine = create_engine(
r'oracle+cx_oracle://{username}:{password}@{service_name}'.format(username=username, password=password,
service_name=service_name),
case_sensitive=False)
self.session_maker = sessionmaker(bind=self.engine, autoflush=False, autocommit=False)
# Database name must be injected into every table definition; this is why tables must be procedurally generated.
self.Base = declarative_base() # base class for all database tables
self.build_tables(database)
def make_session(self):
"""Create a read-only …Run Code Online (Sandbox Code Playgroud)