Softartisan Officewriter does not create excel format with .xlsm extension - xlsm

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.

Related

How to programmatically open and modify ODT file from Calc Macro

I am writing a Macro programm in a LibreOffice Calc spreadsheet. This macro should do the following (amongst other things):
open an existing ODT text document as a template
search and replace some strings with new values
save a copy of this as a new file
generate and open a PDF version
Is this possible somehow using LibreOffice Basic only? I have found nothing in the Libreoffice docs and examples and only this slightly related answer here on SO: How to programatically modify Open/Libre Office odt document?
Thanks!
open an existing ODT text document as a template
The method to open a document is loadComponentFromURL, for example https://help.libreoffice.org/6.4/en-US/text/sbasic/shared/stardesktop.html. There is nothing especially difficult about opening a document in Writer from a Calc macro, as LibreOffice components are well integrated. Remember to use the object returned from opening the document instead of ThisComponent.
search and replace some strings with new values
Andrew's Macro Document section 7.14. Search And Replace shows some ways to do this.
save a copy of this as a new file
The command is storeAsURL which is like "save as", not to be confused with storeToURL which would modify the existing file. See https://wiki.openoffice.org/wiki/Saving_a_document.
generate and open a PDF version
Generating a PDF is like any other save. The only difference is that the export filter writer_pdf_Export must be specified. An example is at https://ask.libreoffice.org/en/question/178818/how-i-export-pdf-using-macro/.
As for opening the PDF, what application do you want to open it? LibreOffice Draw can open a PDF although it's not a normal PDF viewer. Shell can call the viewer of your choice.

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

Using Spreadsheet::XLSX, how do I copy formats from one worksheet to another?

I'm using Perl v5.12.3 on Mac OSX Lion. I'm using the latest version of the Spreadsheet::XLSX module. How do you copy existing worksheet row, column, and cell formats from one XLSX file to a new file? For cells, I'm currently trying
my $cell = $oldWorksheet -> {Cells} [$row] [$col];
...
$newWorksheet->write( $newWorksheetCurRow, $col, $val, $cell->{Format} )
But it isn't working. For example, the background colors aren't getting copied and I don't even think "{Format}" is a valid attribute of the cell.
Spreadsheet::XLSX doesn't read cell formats so it isn't possible to copy a worksheet formatting like this.
As far as I know there isn't any Perl module, apart from Win32::OLE that reads formatting from an XLSX file.
I'm working on one but formatting support is several months away.
If it's like SpreadSheet::WriteExcel/ParseExcel, then you have to do it all manually. That is, create a new format on the writer side, then copy in all the attributes of the format from the parsed side.

Create Excel file in iPhone programmatically

I want to create a Excel supported file which contains strings and images programmatically. I tried to create a .csv file, but I am not able to .csv file with both string and image.
There are many possibilities. The easiest way is to create CSV-Files but you have to take care which seperators excel uses. For checking that you should create a spreadsheet in excel and save it as csv and take a look into that file using any text-editor.
Another approach is to use SpreadsheetML and here a link to the msdn XML Spreadsheet Reference
Otherwise just create a simple xlsx-file with excel, unzip that file and take a look into that the unziped files.

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.