-2

I have an excel template which was created in "Office 2003",That being said, I need to create a new workbook from this existing template programmatically. Also if there are any things that would cause an error, such as locked cells, hidden formulas, hidden sheets, etc. please mention such.

A few things that might be help full to know

  1. I have upgraded from Office 2003 -> Office 2010, however, the file format is Excel 2007.

  2. There are over 303 rows and 26 columns, each one contains its own unique formula (that is just on one sheet), total there are probably over 700 rows, and 100 columns (before adding any additional worksheets), each containing their own relatively unique formulas.##

  3. Certain cells and worksheets are locked as to prevent user-induced errors, or user tampering with in-cell formulas.

  4. This template is going to be used by several people, all of whom have their own computers. I cannot guarantee that the files will be in the same location on every single users computer.

Software Information:

Visual Studio 2013 Office 2010 Office 2003

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • I have read more than half of the msdn documentation, I have read 3 - 4 different books, the problem being that they do not commonly mention version compatability. – comp_sci_in_game_dev Dec 12 '14 at 20:06

2 Answers2

1

Found a solution!

within vs2013, they offer excel 2007 addin, within that predefined interoperability, there is a way to create a file from a template, the part that was throwing me off was the part of the parameters which shows:

"Type.missing". an example of this code structure would be as follows:

//the #region is simply so that if copied and pasted, the code will make sense, and there will be a label encapsulating the specific code lines. *Note it does not affect the results
#region add workbook from template file
Excel.Application f;
//the following line is written assuming that you would have already made sure that excel was in the Running Objects Table (ROT)
f=(Excel.Application)Marshal.GetActiveObject("Excel.Application");
f.visible=true;
f.Workbooks.Add("C:\\...");
\if there are any questions please comment, I will do my best to explain my own answer
#endregion
0

You need to check EPPlus http://epplus.codeplex.com

EPPlus is a .net library that reads and writes Excel 2007/2010 files using the Open Office Xml format (xlsx).

Avijit
  • 1,219
  • 2
  • 15
  • 28
  • Can it read files from Office 2003? – comp_sci_in_game_dev Dec 12 '14 at 19:55
  • Technically it should be. But I havent tested it. Please read the document. – Avijit Dec 12 '14 at 19:58
  • Ok, thank you, I just wanted to know if it didn't a head of time. – comp_sci_in_game_dev Dec 12 '14 at 19:58
  • You can take a look at http://stackoverflow.com/questions/151005/create-excel-xls-and-xlsx-file-from-c-sharp if this is helpful to you. – Avijit Dec 12 '14 at 20:11
  • Thank you, and as for epplus. I have tested it, id does not seem to work perfectly for any Office 2003 file formats, it isn't horrible, but perhaps I should have mentioned, the rest of the people who would be using it, could possibly still be using office 2003. – comp_sci_in_game_dev Dec 12 '14 at 20:21
  • Sorry, I appreciate your help, but ExcelLibrary did not work either. I am not creating it from scratch, the template already exists, and I have it. However, I need to create a new file from this template, neither EPPlus, nor ExcelLibrary, seems to have been able to do such and all of this is being done in "Visual Studio" with com Interoperability. Let me Edit the original post to give list the different applications this involves. I guess, I could try to save the old template as a more modern template, but then those who are not using office 2007 or newer, cannot use it. – comp_sci_in_game_dev Dec 12 '14 at 20:45