Excel Automation - Compatibility Checker

G

g0ld2k

I am developing a program to automate saving xlsx files to xls. The issue
that I am having is that in the automation, when I save the xlsx as xls the
Compatibility Checker window comes up, and the user must confirm for each
file processed. I have tried to set the checkCompatiblity to false, but that
seems to only help if the format of the file is changing, I am including my
code below, does anyone have any recommendations of a way to get around the
compatibility checker?


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;
using System.IO;

namespace WindowsFormsApplication1
{
class ConvertExcel
{
private String dirName;
private String[] filesToConvert;
private Microsoft.Office.Interop.Excel.Application xlApp;
Workbook wb;

public ConvertExcel()
{
dirName = @"C:\\No_Backup\\Excel\\";
filesToConvert = Directory.GetFiles(dirName, "*.xlsx");
startExcel();
for (int i = 0; i < filesToConvert.Length; i++)
{
if (!filesToConvert.Contains("~"))
{
openFile(filesToConvert);
saveAsXLSX(filesToConvert);
}

}
quitExcel();

}

public void startExcel()
{
xlApp = new Microsoft.Office.Interop.Excel.Application();

if (xlApp == null)
{
Console.WriteLine("EXCEL could not be started. Check that
your office installation and project references are correct.");
return;
}
xlApp.Visible = true;

}

private void openFile(String fileName)
{
wb = xlApp.Workbooks.Open(fileName, Type.Missing, Type.Missing,
Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
wb.CheckCompatibility = false;
}

private void saveAsXLSX(String fileName)
{
wb.SaveAs(@"C:\No_Backup\Excel\test.xls",
XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing);
wb.Close(false, null, null);
}

private void quitExcel()
{
xlApp.Quit();
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top