Shawn
Shawn

Reputation: 228

Compile program to run with older version of Excel

Currently i am making an program that exports data to excel. My computer is runing windows 7 and office 2013, but the program should be able to run on older pcs whit windows XP and office 2010. When i run the app on xp it returns an error that .

I found out that i should compile for an older version of office. I tried to dowload o2010pia installer but after trying to install the program it closes after the load bar movin 10% or so.

this is my refference

using Excel = Microsoft.Office.Interop.Excel;


Excel.Workbook xlWorkBook;
            Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;

            xlWorkBook = xlApp.Workbooks.Add(misValue);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            string rangeborder = (4 + student.GetLength(0)).ToString();

            xlWorkSheet.get_Range("B4", "E" + rangeborder).Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
            xlWorkSheet.get_Range("B4", "E" + rangeborder).Borders.Color = ColorTranslator.ToOle(Color.Black);
            xlWorkSheet.get_Range("B4", "E" + rangeborder).Borders.Weight = 3d;
            xlWorkSheet.get_Range("B4", "E" + rangeborder).Borders.LineStyle = Excel.XlLineStyle.xlContinuous;

            Excel.Range er = xlWorkSheet.get_Range("C:D", System.Type.Missing);

            er.EntireColumn.ColumnWidth = 25;

            xlWorkSheet.Range[xlWorkSheet.Cells[2, 2], xlWorkSheet.Cells[2, 6]].Merge();

            xlWorkSheet.Cells[4, 2] = " ";
            xlWorkSheet.Cells[4, 3] = "a";
            xlWorkSheet.Cells[4, 4] = "b";
            xlWorkSheet.Cells[4, 5] = "c";

            for (int x = 0; x < student.GetLength(0); x++)
            {
                xlWorkSheet.Cells[x + 5, 2] = x;


            }

            xlWorkBook.SaveAs(path + "abc" + printDatum() + "_"+ ".xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
            xlWorkBook.Close(true, misValue, misValue);
            xlApp.Quit();

            releaseObject(xlWorkSheet);
            releaseObject(xlWorkBook);
            releaseObject(xlApp);

Upvotes: 0

Views: 241

Answers (2)

Patrik
Patrik

Reputation: 1382

Alternatively you can use a third-party library like NetOffice, which wraps the Office-Communication so you don't have to bother about the version.

There is already a SO Article with an answer which will help you.

Features provided by NetOffice

  • Office integration without version limitations
  • All features of the Office versions 2000, 2002, 2003, 2007, 2010, 2013 are included
  • Syntactically and semantically identical to the Microsoft Interop Assemblies
  • No training if you already know the Office object model, use your existing PIA code
  • Usable with .NET version 2.0 or higher
  • No dependencies, no interop assemblies, no need for VSTO

Upvotes: 1

Patrik
Patrik

Reputation: 1382

When I encountered that problem, I figured that only compiling on a system with such an old office was the solution.

The 2010 PIA package helps you when its up to the deployment of your app, but sadly you need to compile it on a machine having office 2010.

I personally worked on the app using my computer with office 2013. When it came to the deployment, I used a virtual machine having office 2010 to compile the app.

Upvotes: 1

Related Questions