Reading Excel 2010 file saved in 2007 - ado.net

I have created a workbook in Excel 2010. This file allows users to enter data on various worksheets and import it in to our systems using a Web Application. The file is connected to using the following connection string:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=myfilename.xlsx;Extended Properties='Excel 12.0 XML; HDR=Yes; IMEX=1;'
Everything works fine. However, if the Excel 2010 file is opened in Excel 2007 and simply saved, then the import no longer works. I get the old "Failed to connect to Excel File: External table is not in the expected format." error.
The saved file is not open when I perform the import.
I'm not quite sure what I need to do. The connection string seems correct for Excel 2007 and 2010. Does saving an Excel 2010 file by opening it in Excel 2007 somehow corrupt it? The file extension is the same... xlsx. The workbook is password protected, has hidden sheets, etc. which are necessary.

Related

Opening Excel File with ClosedXML throws System.ArgumentNullException

Every time I try to open an Excel file with ClosedXML with the following code
XLWorkbook spreadsheetDocument = new XLWorkbook("Sample.xlsx");
I get a System.ArgumentNullException. However, I made a copy of that file in Excel, I renamed it and I have opened it succesfully. I compared both files using the Open XML Productivity Tool and I got the following output.
I wonder if those differences have something to do with the fact that I cannot open Sample.xlsx using ClosedXML. Thank you for your help.

Softartisan Officewriter does not create excel format with .xlsm extension

I want to create new excel sheet with .xlsm extension by using softartisan dll, however in create method of softartisan does not have xlsm format. It has only .xls and .xlsx formats.
My new excel contains macros hence I need .xlsm format.
Code is as follows
Dim xla As New ExcelApplication
errWb = xla.Create(FileFormat.Xls) ''Or errWb = xla.Create(FileFormat.Xlsx)
I want file in .Xlsm format
If anybody knows please suggest.
OfficeWriter does not support manipulating or creating Excel macros/VBA through the API because of the potential security risks. Creating a new XLSM file that doesn't contain any macros has limited usefulness. Hence the XLS and XLSX are the only file formats that can be created from scratch using OfficeWriter.
OfficeWriter does support manipulating existing XLSM files, but the macros/VBA are not accessible. If you need to create a new report that contains certain macros, we recommend that you create an XLSM file in Excel that contains the macros that you need. Then open and modify that file with ExcelApplication. The XLSM file can event be blank, except for the macros that you need.
Dim xla As ExcelApplication = new ExcelApplication()
Dim wb As Workbook = xla.Open("myStartingTemplate.xlsm")
...
Note: I work for SoftArtisans, makers of OfficeWriter.

Can I use a Microsoft Word file as a report template for JasperReports?

I have several model contracts in Microsoft Word files with as many as 20 pages per file). I would like to use Jasper Reports to fill out these contracts.
I tried importing the doc file into iReport, but that is not working.
Is there a way to convert a Microsoft Word file to a JasperReport template?
Try to convert the doc into excel and than use the excel as datasource in ireport.
Edit: Based on OP's comment.
You can not use a Microsoft word file as a JasperReport template. You will need to create a JRXML file for JasperReports. It is possible to use rtf or html as source for text fields but the final formating of such field is rather pure.
Your other option is to not user JasperReports and manipulate the Microsoft Word files directly using Apache Poi.

Error using the User Defined function of Excel in Matlab [duplicate]

This question already exists:
Closed 10 years ago.
Possible Duplicate:
Excel Addin Error #NAME?
I think it is a follow-up query to my earlier reported issue concerning User defined function in Excel.
I am able to use the function in Excel when used Manually, but when I write to an excel file using Matlab using xlswrite, it gives an error #NAME?
I am attaching the screenshots of the both when entered manually and when using the function through Matlab.
Thanks
EDIT :
Thanks a lot. I have stored the VBA function as an Excel addin here :
C:\Users\Administrator\AppData\Roaming\Microsoft\Addins
Here is what I saw about Excel Add-ins not loaded when used in Automation :
http://www.excelforum.com/excel-programming/472145-calling-excel-macro-from-vb-6-app-problem.html
I am attaching the small snippet of the code from chi_squared() here :
Function Chi_Squared(act, exp, Optional df)
This is how I write to an excel file in Matlab :
Formula_chisqr={[ '=chi_squared(' 'O2:O22' ',' 'M2:22' ')']};
[status, message] = xlswrite1(ExcelFilename,Formula_chisqr,sheetname, Location_Agg);
I also tried giving the complete path as suggested. But it did not work.
Thanks
You have to specify the workbook where the UDF defined. Even if your function is it your PERSONAL.XLSB file. You don't have to do it only if UDF is defined in the same file where you use it.
For example,
='myFunctions.xlsb'!chi_squired(O2:O21,P2:P21)
If myFunctions.xlsb is not opened you may need to specify full path to the file.
If you want to be able to call UDF in any file without specifying the file name, you need to save the file as Add-in, and then enable it in Options - Add-ins - Manage Add-ins.
Another idea: When you use XLSWRITE provide file name with extension XLSX, like test.xlsx, not just test. By default MATLAB saves files with XLS extention in older format. It looks like when you open such file in newer version of Excel (2007/2010) the compatibility mode does not allow macros or UDFs to run.
When you open the Excel as a COM server, the UDF's and Add-ins are not loaded by default. So, you need to first load the add-ins if you would like to use the add-in your Excel file.
Here is the small code snippet in Matlab which loads the add-ins before opening the Excel file.
Excel = actxserver ('Excel.Application');
Excel.Workbooks.Open('C:\YourAddInFolder\AddInNameWithExtension');
Excel.Workbooks.Item('AddInNameWithExtension').RunAutoMacros(1);
File='C:\YourFileFolder\FileName';
if ~exist(File,'file')
ExcelWorkbook = Excel.Workbooks.Add;
ExcelWorkbook.SaveAs(File,1);
ExcelWorkbook.Close(false);
end
Excel.Workbooks.Open(File);
Source : Mathworks

How to most effectively automate repetitive Excel task?

I want to automate Excel using Perl to do the following task(s):
For a list of Excel .xls files, do the following:
Open the file
Set Format to CSV
Save the file under the original filename and directory, but replace the extension "xls" with "csv"
Close the file
End
I found how to open files, even how to save them. I did not find how to change the fileformat/save as a different format. There shall be no user dialogs popping up, it should be fully automated. The Excel file list I can generate myself, a parameterized "find" or maybe "dir" should suffice.
If you are using Excel automation a great help is Excel itself. Use the VBA environment (Alt+F11) to get help for the Excel objects you want to use.
The objectbrowser (F2) is very valuable.
Workbook.SaveAs([Filename], [FileFormat], [Password], [WriteResPassword], [ReadOnlyRecommended], [CreateBackup], [AccessMode As XlSaveAsAccessMode = xlNoChange], [ConflictResolution], [AddToMru], [TextCodepage], [TextVisualLayout], [Local])
Searching for CSV in the object browser will show Excel constants with their values, since you probably cannot use these Excel constants in Perl.
See Spreadsheet::ParseExcel and xls2csv, they will help you.