Perl Excel preview problem in Outlook - perl

I am generating Excel report in Perl.
I am using the Formula in the cell, it's working fine, but in Outlook when I see through preview file, the cell is showing something like Spreadsheet::WriteExcel::Format=HASH(0x87d6d04) instead of total.
I am using simple forumulas only, like =sum(B1:B10) or =sum(A1,B2).
How to fix this?
outlook excel preview

You probably need to use the write_formula method rather than the plain write one.
For example,
$worksheet->write_formula(1, 0, '=SIN(B1:B10)');
From the documentation on CPAN for Spreadsheet::WriteExcel

In your code:
$worksheet->write(..., $format05,$font );
You have an unnecessary trailing $fontat the end of that method call which is being passed to write_formula() (via write()) as an optional result for the formula.
That is what is showing up as the formula result in Outlook.

Related

Progress 4gl Creating a .xlsx file without excel

Version: 10.2b
I want to create a .xlsx file with progress but the machine this will run on doesn't have excel.
Can someone point me in the right direction about how to do this.
Is there a library already written that can do something like this?
Thanks for any help!
The project was moved to the Free DocxFactory Project.
It was rewritten in C++ with Progress 4GL/ABL wrappers and tutorial.
It is 300x times faster, alot of new features were added including barcodes, paging features etc.
and it's completely free for private and commercial use without any time or feature limits.
HTH
You might find this to be useful: http://www.oehive.org/project/libooxml although it appears that there is nothing there right now. There might also be an older version of that code here: http://www.oehive.org/project/lib
Also -- in many cases the need to provide data to Excel can be satisfied with a Tab or Comma delimited file.
Another trick is to create an HTML table fragment. Excel imports those quite nicely.
A super simple example of how to export a semi-colon delimited file from a temp-table. In 90% of the cases this is enough Excel-support - at least it has been for me.
DEFINE STREAM strCsv.
DEFINE TEMP-TABLE ttExample NO-UNDO
FIELD col1 AS CHARACTER
FIELD col2 AS INTEGER.
CREATE ttExample.
ASSIGN ttExample.col1 = "ABC"
ttExample.col2 = 123.
CREATE ttExample.
ASSIGN ttExample.col1 = "DEF"
ttExample.col2 = 456.
OUTPUT STREAM strCsv TO VALUE("c:\test\test.csv").
FOR EACH ttExample NO-LOCK:
EXPORT DELIMITER ";" ttExample.
END.
OUTPUT STREAM strCsv CLOSE.

Perl code for inserting graphs into MS Word

I am using Perl for automation for report generation. Reports are generated in HTML. same report can be opened in MS word format. tables generated in HTML look good in Word too.
Problem:
Ineed to also insert few graphs in the report. For HTML, I am using SVG::TT::Graph::Line Perl module to generate the graphs.
The idea here is to keep single HTML file that contains all tables and graphs.
Currently every thing looks good in HTML. but when i open the same file in Word, the graphs are replaced by data (because I am using SVG Perl module).
Just wondering what would be the best way to generate graphs for Word file that doesn't change my code much.
Any suggestions with the Perl modules to be used would be much appreciated.
I haven't tried this, but the only thing I can think of is to use ImageMagick to convert the SVG to PNG and then use a Data URI to embed the image in the HTML.

Setting an Excel worksheet's custom page size (not the printable area) from Perl

Long story short, all I'm really attempting to do is print my reports on half sheets. I had Kinko's chop a pack of printer paper in half and my laser printer is perfectly happy to suck them in and print the reports properly, if the paper size of the Excel report is set to exactly 8.5" x 5.64".
That can be done easily in Excel, but it's the one and only adjustment, in my project, I wasn't able to automate with Perl using Spreadsheet::WriteExcel. The CPAN documentation states that you can pick from some of the default sizes normally available with Excel, but doesn't provide an option to specify your own paper size.
Even if you establish the custom size you need in Excel beforehand, making it available in future spreadsheets, as one of your selectable paper sizes, there doesn't seem to be an index, using set_paper($index), that would specify that newly established custom size.
Thank you in advance!
#!/usr/local/gnu/bin/perl --
use strict;
use warnings;
use Spreadsheet::WriteExcel;
my $repWB = Spreadsheet::WriteExcel->new('../tmp/test.xls');
my $repWS = $repWB->add_worksheet('AA');
$repWS->set_paper(1);
Since VBScript can do many of these things natively, maybe you could try embedding the necessary VBScript into your main Perl script using Inline:WSC.
You could determine the needed VBScript by recording an Excel macro of you setting the print size. Then embed that code into your main Perl script.
I am the author of Spreadsheet::writeExcel.
As far as I know there isn't an option in Excel to set a custom paper size. This is usually set in the printer (correct me if I am wrong).
Excel can store printer information along with the workbook data so there may be a workaround.
Can you send me a single sheet workbook with data in cell A1 only and a copy with the custom page set and I'll take a look to see if it is possible.
P.S. The available option B5 (index 13) in landscape mode is fairly close: 8.27" x5.83". Or the undocumented "Organiser L" (index 129) which should be half Letter size: 8.5" x 5.5".

How to write formula in Excel sheet which is stored in the perl variable

use strict
use Spreadsheet::WriteExcel;
my $Workbook = Spreadsheet::WriteExcel->new('cw.xls');
my $Worksheet = $Workbook->add_worksheet('MRD');
my $Formula= "A10+B10/2";
$Worksheet->write_formula(1,2,'='.($Formula));
exit;
Error getting:
Couldn't parse formula: =A10+B10/2;
Note : In the Formula that I am using contain across sheet data calling.
When I am Pasting it in the excel sheet manually its working fine but through program I am unable to put it in the sheet.
Please if any one came across this problem or has solution let me know.
If you see the documentation of Spreadsheet::WriteExcel module, it states in the DIAGNOSTICS section that:
Couldn't parse formula ...
There are a large number of warnings which relate to badly formed formulas and functions. See the "FORMULAS AND FUNCTIONS IN EXCEL" section for suggestions on how to avoid these errors. You should also check the formula in Excel to ensure that it is valid.
There is no problem storing a formula in a variable and passing it to write_formula(). In fact your own snippet above proves that it works.
So the problem is with the formula that you are trying to write. Since you haven't posted the formula it is hard to guess what the problem might be but here are some formula debugging tips from the docs:
Verify that the formula works in Excel (or Gnumeric or OpenOffice.org).
Ensure that it isn't on the Caveats list shown above. (In the docs).
Ensure that cell references and formula names are in uppercase.
Ensure that you are using ':' as the range operator, A1:A4.
Ensure that you are using ',' as the union operator, SUM(1,2,3).
Ensure that the function is in the above table. (In the docs).
P.S. The leading '=' isn't required when you are using write_formula() so you can just use:
$Worksheet->write_formula(1, 2, $Formula);

How do I export a Crystal Report to a Unicode text file?

I'm trying to export a Crystal Report to a text file, while preserving any Unicode characters that are found within. By default, Crystal Reports seems to export to an ANSI text file.
Here is a highly simplified version of what I'm doing:
Dim objCRReport As CRAXDRT.Report
[...]
objCRReport.ExportOptions.FormatType = 8 'crEFTText
objCRReport.ExportOptions.DestinationType = 1 'crEDTDiskFile
objCRReport.ExportOptions.DiskFileName = "C:\reportInTextFormat.txt"
objCRReport.Export blnPromptUser
Since it creates a file in ANSI format, I lose any special characters that were found within the report. These characters are all fine when you view the Crystal Report directly.
Please note that I am referencing the "Crystal Reports 9 ActiveX Designer Runtime Library" specifically.
I want to point out that I've tried pre-creating a Unicode file with the same name prior to the export, hoping the Crystal code would notice the file, and append to it rather than creating an ANSI file, but unfortunately this is not the case.
I then thought I could get around this problem (ninja style) by just exporting to an RTF file (which preserves the characters), then reading the contents of this RTF (minus the formating). I would then create a Unicode text file myself, writing the RTF contents to it. Unfortunately, to achieve this, I had to look into using a RichTextBox, but encountered a slew of problems with that. I think I'd have more success in VB.Net, but unfortunately I'm stuck with VB6 for this task.
After trying those approaches, I found an article that seems to suggest that Crystal Reports 9 supports exporting to a Unicode Text file, but I have yet to see it work. It mentions that the print engine supports it, so I'm going to look deeper to see if I can invoke it, in case the .export isn't doing so itself (which I doubt).
It turns out Crystal relies heavily on the printer driver for Unicode support, so I decided to look into that. Turns out the printer driver had to support Unicode, and this was the case on my test environment. While this was interesting to find out, it didn't solve my problem - I already had a compatible printer driver.
So, finally: after a few days of trying to find a solution to this, my boss decided it was time to cut our losses, and we instead planned for a re-design of the feature, without involving Crystal Report to Text exports. I am still, however, very interested in how to export to a Unicode text file with Crystal - so please do answer if you know how.