简体   繁体   English

SaveAs()不能按预期工作

[英]SaveAs() doesn't work as expected

I 'm trying to open an excel file that already exist, do some operations and the save the excel file with the same name. 我正在尝试打开一个已经存在的Excel文件,执行一些操作,然后用相同的名称保存Excel文件。

var xls = new ActiveXObject("Excel.Application");
xls.visible = true;
xls.DisplayAlerts=false;
var wb=xls.Workbooks.Open("C:\\test.xls");
xls.Range("A1","B1").Interior.ColorIndex=37;
xls.Range("C1","D1").Interior.ColorIndex=37;
xls.Range("A1:D1").Merge();
wb.SaveAs("C:\\test.xls");
xls.Quit();

Bu, im not able to save, i'm been promptd sayin file already exist, do u want to save, etc... Any suggestion pls... Bu,我无法保存,系统提示我说文件已存在,您是否要保存,等等。任何建议。


I changed my code as below: 我将代码更改如下:

var xls = new ActiveXObject("Excel.Application");
xls.visible = true;
xls.DisplayAlerts=false;
var wb=xls.Workbooks.Open("C:\\test.xls");
xls.Range("A1","B1").Interior.ColorIndex=37;
xls.Range("C1","D1").Interior.ColorIndex=37;
xls.Range("A1:D1").Merge();
wb.SaveAs("C:\\newTest.xls");
xls.Quit();

The file is now saved, but the problem is with formatting. 现在已保存文件,但是问题出在格式化上。 The original file test.xls is a tab delimited file saved as .xls file. 原始文件test.xls是制表符分隔的文件,另存为.xls文件。 after doing some modifications to the file saving as newTest.xls, when I try to open, it says that the formatting is not good and do you want to open? 对文件另存为newTest.xls进行一些修改后,当我尝试打开时,它说格式不好,您要打开吗? when I click yes, it opens the file but without the modifications done. 当我单击“是”时,它将打开文件,但未完成修改。

Any suggestions? 有什么建议么?

You are trying to save the file with the same name. 您正在尝试使用相同的名称保存文件。 To do this don't use SaveAs but instead use the regular Save . 为此,请不要使用SaveAs ,而应使用常规的Save

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM