Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows资源管理器强制导入excel_Windows_Excel - Fatal编程技术网

Windows资源管理器强制导入excel

Windows资源管理器强制导入excel,windows,excel,Windows,Excel,我想在windows资源管理器windows 7中添加一个上下文菜单项,以便将所选文件导入excel并启动导入对话框 我设法按照本指南添加了条目: 但当它打开文件时,将跳过“导入”对话框,并在电子表格中打开该文件 编辑:我搜索了exe开关,但是我发现的那些开关对这个没用! 编辑2:根据ElectricLlama的要求提供更多背景信息 额外背景: 需要将大量文本文件导入excel。不是CSV 目前它们的宽度是固定的,但在不久的将来肯定会改变。 我打开它们来转换它们,并添加一些额外的信息作为列。

我想在windows资源管理器windows 7中添加一个上下文菜单项,以便将所选文件导入excel并启动导入对话框

我设法按照本指南添加了条目:

但当它打开文件时,将跳过“导入”对话框,并在电子表格中打开该文件

编辑:我搜索了exe开关,但是我发现的那些开关对这个没用! 编辑2:根据ElectricLlama的要求提供更多背景信息

额外背景: 需要将大量文本文件导入excel。不是CSV 目前它们的宽度是固定的,但在不久的将来肯定会改变。 我打开它们来转换它们,并添加一些额外的信息作为列。
程序X生成一个带有空格的表格-->Excel以格式化此表格并添加信息-->程序Y直接打开Excel文件

,因此我使用regedit在windows注册表中设置了一个选项,让它启动python脚本,该脚本将处理对Excel.exe的解析和调用。文件类型为无扩展名的文件,python位于PATH windows变量中。如果您想知道,regedit导出也会转义引号:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\import with excel]
@="Convert and Open with Excel"

[HKEY_CLASSES_ROOT\*\shell\import with excel\command]
@="python \"path to python script\" \"%1\""
python脚本非常凌乱,非常适合我的需要,但这里是:

import csv, os, sys

#If there are no arguments stop everything
if len(sys.argv) > 0:
    file = sys.argv[1]
else: sys.exit()

fileout = file + ".csv"

data = open(file, "r")
open(fileout, 'w').close() #cleans the file

dataout = open(fileout, "a")

# using the python csv lib, please look for info on it for further explanation
with open(fileout, 'wb') as csvfile:
    spamwriter = csv.writer(csvfile, dialect='excel')

# I needed a special handling for the first line, that's why I used the i < 2
    i = 1
    for line in data:
        line = line.split()
        lineout = [] # clean the list after each line is parsed
        if i < 2: lineout.append("")
        for item in line:
             if item != "\"": lineout.append(item.replace("\"", ""))
        spamwriter.writerow(lineout)

        i += 1
data.close()
dataout.close()

# launches excel.exe with the fileout argument
os.system("start Excel.exe \""+ fileout + "\"")

然后,我在excel中打开了我想要的csv文件。实际上,这种方法比手动选择Excel导入窗口中的每个选项更快。

您可以构建一个VBScript,使用Excel对象模型来完成这一切。如果你感兴趣,请发回。是的,我会对VB脚本感兴趣!它是通过windows还是excel内部调用的?它是从windows调用的-让我做一些调查,然后返回给您。似乎没有一种编程方式来显示导入对话框。所有的文件都一样吗?它们是固定宽度的吗?您打开它们是为了转换它们,编辑它们并以不同的格式保存,还是只是查看它们?回答为编辑,ElectricLlama!