I want to use EPPlus for Excel import/export in a C++/CLI project.
When I try to access a single cell with the following code I get a compilation error:
ExcelPackage^ ep = gcnew ExcelPackage(gcnew System::IO::FileInfo("Test.xlsx"));
ExcelWorksheets^ sheets = ep->Workbook->Worksheets;
ExcelWorksheet^ sheet = sheets[1];
ExcelRange^ range = sheet->Cells[1, 1]; // this line causes C3252
Full error message:
error C3252: 'CellStore::Finalize': cannot reduce accessibility of a virtual method in a managed type
note: This diagnostic occurred while importing type 'CellStore ' from assembly 'EPPlus, Version=4.5.2.1, Culture=neutral, PublicKeyToken=ea159fdaa78159a1'.
note: This diagnostic occurred while importing type 'OfficeOpenXml::ExcelWorksheet ' from assembly 'EPPlus, Version=4.5.2.1, Culture=neutral, PublicKeyToken=ea159fdaa78159a1'.
Oddly enough this works in C#:
ExcelPackage ep = new ExcelPackage(new System.IO.FileInfo("Test.xlsx"));
ExcelWorksheets sheets = ep.Workbook.Worksheets;
ExcelWorksheet sheet = sheets[1];
ExcelRange range = sheet.Cells[1, 1]; // no error here
Is this something that ist just not supported by C++/CLI or ist there an error in my code or even in the EPPlus-library?
Related
how to convert the following VBA code to c++ builder in OLE? Thanks.
Range("A10:B28").Select
ActiveSheet.Shapes.AddChart2(240, xlXYScatter).Select
ActiveChart.SetSourceData Source:=Range("Sheet1!$A$10:$B$28")
ActiveSheet.Shapes("test1").IncrementLeft -288.5293700787
ActiveSheet.Shapes("test1").IncrementTop -39.7059055118
I have tried the following code, the c++ builder crash at last line
#include <excel_2k.h>
outXL = Variant::CreateObject("excel.application");
outXL.OlePropertySet("Visible", true);
outWorkbooks = outXL.OlePropertyGet("Workbooks");
outWorkbook = outWorkbooks.OleFunction("Open", "D:\\test.xls");
outWorkSheets = outWorkbook.OlePropertyGet("Worksheets");
outActiveSheet = outWorkbook.OlePropertyGet("Worksheets", 0);
outActiveSheet.OlePropertyGet("Activate");
Range=outActiveSheet.OlePropertyGet("Range",
outActiveSheet.OlePropertyGet("Cells",5,1),
outActiveSheet.OlePropertyGet("Cells",20,2));
Chart = outActiveSheet.OlePropertyGet("Shapes").OleFunction("AddChart2");
//=========This line Dump ERROR=========
Chart.OlePropertySet("ChartType",xlXYScatter);
IDK, if this is the answer, but ISTM you need to modify the code here
Chart = outActiveSheet.OlePropertyGet("Shapes").OleFunction("AddChart2", 240, xlXYScatter);
That is the way it is called in the VBA. You just have OleFunction("AddChart2")
What is the value of Chart after the function call?
I have fixed this issue, please reference the following code...
Chart = outXL.OlePropertyGet("Charts").OleFunction("Add");
Chart.OlePropertySet("ChartType", xlXYScatter);
Range=outActiveSheet.OlePropertyGet("Range",
outActiveSheet.OlePropertyGet("Cells",iDrawRowFrom,iDrawColFrom),
outActiveSheet.OlePropertyGet("Cells",iDrawRowTo,iDrawColTo));
Chart.OleProcedure("SetSourceData", Range);
Chart.OleFunction("Location", 2, strOutSheetName.c_str());
I'm having the following error usiing SmartPlant P&ID (SPPID) automation library Llama (Interop.Llama.dll):
System.Runtime.InteropServices.COMException (0x80000008): No DBConnect for Data_Dictionary
at Llama._LMEquipments.Collect(LMADataSource& DataSource, _LMAItem& Parent, String& RelationshipName, LMAFilter& Filter)
Here is the code that calls it:
Dim objDS As Llama.LMADataSource
Dim objEquips As Llama.LMEquipments
objDS = New Llama.LMADataSource
objDS.ProjectNumber = Project.SPPIDName & "!" & Project.SPPIDName
objDS.SiteNode = Project.SiteServer
objEquips = New Llama.LMEquipments
objEquips.Collect(objDS) ' throws Exception
Any ideas on what might be wrong?
SPPID is an engineering tool used to develop and manage piping and instrumentation diagrams. Llama is an automation library supplied with SPPID.
This means that your code can't find that specific project in SPPID available plant structures database. Beware that the ProjectNumber string is case sensitive .
In my case, all I had to do was to change project name, from PF2_REF to PF2_Ref (replaced last two letters for lowercase equivalents).
Please help me with the below issue.
I have to read data from excel .
I have created JSPDynpage component and followd below link :
http://help.sap.com/saphelp_sm40/helpdata/en/63/9c0e41a346ef6fe10000000a1550b0/frameset.htm below is my code. I am trying to read excel file using apache poi 3.2 API
try
{
FileUpload fu = (FileUpload)
this.getComponentByName("myfileupload");
// this is the temporary file
if (fu != null) {
// Output to the console to see size and UI.
System.out.println(fu.getSize());
System.out.println(fu.getUI());
// Get file parameters and write it to the console
IFileParam fileParam = fu.getFile();
System.out.println(fileParam);
// Get the temporary file name
File f = fileParam.getFile();
String fileName = fileParam.getFileName();
// Get the selected file name and write ti to the console
ivSelectedFileName = fu.getFile().getSelectedFileName();
File fp = new File(ivSelectedFileName);
myLoc.errorT("#fp#"+fp);
try {
//
**FileInputStream file = new FileInputStream(fp);** --> error at this line
HSSFWorkbook workbook = new HSSFWorkbook(file);
myLoc.errorT("#workbook#"+workbook);
//Get first sheet from the workbook
HSSFSheet sheet = workbook.getSheetAt(0);
myLoc.errorT("#sheet#"+sheet);
//
} catch(Exception ioe) {
myLoc.errorT("#getLocalizedMessage# " + ioe.getLocalizedMessage());
}
Error :
#getLocalizedMessage# C:\Documents and Settings\10608871\Desktop\test.xls (The system cannot find the path specified)
at line FileInputStream file = new FileInputStream(fp);
I have created the PAR file and deploying it on server.
Thanks in Advance,
Aliya Khan.
i resolved the problem, i was passing the worng parameter instead of f
FileInputStream file = new FileInputStream(f);
I want to compress and move the file using vb.net and SevenZipSharp.dll
c:\Backup\FULLBackup.bak -> c:\Archive\20130322.7z
I added a reference SevenZipSharp.dll
Imports SevenZip
SevenZip.SevenZipCompressor.SetLibraryPath(System.AppDomain.CurrentDomain.BaseDirectory & "\SevenZipSharp.dll")
Dim theCompressor As New SevenZipCompressor()
With theCompressor
.ArchiveFormat = OutArchiveFormat.SevenZip
.CompressionMode = CompressionMode.Create
.CompressionMethod = CompressionMethod.Default
.DirectoryStructure = False
.CompressionLevel = CompressionLevel.Normal
End With
theCompressor.CompressFilesEncrypted("c:\Archive\20130322.7z","c:\Backup\FULLBackup.bak")
I get an error : Can not load 7-zip library or internal COM error! Message: library is invalid.
I think it's simply the fact that the LibraryPath must not point to "SevenZipSharp.dll" but to "7z.dll".
http://blog.jongallant.com/2011/10/7-zip-dll-file-does-not-exist.html#.UaOLk0DxobA
I am trying to execute the following code to convert a xlsm file to csv :
//Workbook wbk = new HSSFWorkbook(new FileInputStream(new File("myFile.xls")));
Workbook wbk = new XSSFWorkbook(new FileInputStream(new File("myFile.xlsm")));
for (int i = 0; i < wbk.getNumberOfNames(); i++) {
if (wbk.getNameAt(i).getNameName().startsWith("START\\")) {
// Get SheetName
sheetName = wbk.getNameAt(i).getSheetName();
// Get csv Filename
csvFilename = generateFileName(wbk.getNameAt(i).getNameName(), currentDate);
// Starting row index for this sheet
startingRowIndex = getStartingRowIndex(wbk, i);
// Max column index for this sheet
maxColumnIndex = getMaxColumnIndex(wbk, wbk.getSheet(sheetName));
// Convert sheet to csv
toCSV(csvFilename, startingRowIndex, maxColumnIndex, wbk, sheetName);
}
}
-Xmx argument is setted to 1024 and i use a xslm file.
This file is 15 Mo.
I get this error "java.lang.OutOfMemoryError: Java heap space" on the first line.
With the same file in xls format (50 Mo), it works great.
I can't change the Xmx argument and I can't use other API than POI.
I read in others messages that the better way is to use the SAX API for this kind of memory problems.
However, in my file, all sheets and all rows don't need to be extracted in CSV.
That is why I use "wbk.getNumberOfNames()" to get all the defined names (in the name manager) and to know the sheets to convert.
Do you know how i can access these properties using SAX API ?
Thanks.
Regards.
The following Apache POI code example uses SAX parser to convert XLSX file to CSV.
http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java