Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET Excel
Hi,
I am totally new to C# and .net. I have the task of debugging an application which was written by someone who has long gone. The problem is as follows.
 
The application opens an excel workbook. If you edit the excel workbook and then save it from the application it works fine in every case I have tried except for one case. It does not work if a cell containing a formula cell is selected and then the bottom right-hand corner is selected and dragged to copy the formula into the cell below. It even works fine if I select the formula cell, do ctrl-C and then ctrl-V in another cell. It is just the dragging thing which seems to cause a problem.
 
The call is as follows:
currentwb.GetExcelWorkbook().SaveAs(
FileNameWithCxnID,
56,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Excel.XlSaveAsAccessMode.xlNoChange,
Missing.Value,
false,
Missing.Value,
Missing.Value,
Missing.Value);
 
I am totally stumped with this one right now. Can anyone give me any pointers to get me started.
 
Many thanks to anyone who can give even the tiniest hint!
Posted 25-Mar-13 8:57am
Edited 25-Mar-13 9:00am
v3
Comments
Maciej Los at 25-Mar-13 13:59pm
   
Code, please, code!
Jackie Lloyd at 25-Mar-13 14:01pm
   
yeah, sorry, I just realised and was adding it as you asked! I don't know what else to put in.
Maciej Los at 25-Mar-13 14:16pm
   
Is that all your code???
Jackie Lloyd at 26-Mar-13 5:20am
   
There's a lot of code, and I am not allowed to copy the whole lot due to security. I am just starting to understand it all then should be able to post more relevant bits. I really just wondered if anyone knew any reason why the save would not work in this case but would in all the others, or could give me any leads to get me started. Is there anything different about saving a workbook when the click and drag has been performed. I have noticed that if I do the click and drag and then another operation afterwards e.g typing in a cell, then the save does work. So it must be that the click and drag leaves it in an odd state.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Well, I dont know exactly what you have to write, but I think the standard way Excel copy is the Cell.Value, and you want Excel.Formula. Thats what I do when that is needed anyway, but I dont know how to do it as you have specified.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I think that you are calling the SaveAs methods, there you can refer to the MSDN: http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.saveas(v=vs.80).aspx[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Having looked into this, researched on the web etc I have found lots of cases where excel behaves in an odd, unhelpful manner. Workarounds seem to be suggested rather than logical solutions. So, I am going to create a macro which will cause an operation to be performed on the spreadsheet before every save. This will ensure that the click and drag operation is never the last operation before before every save.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 539
1 Maciej Los 300
2 DamithSL 233
3 Sergey Alexandrovich Kryukov 209
4 BillWoodruff 200
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100