TMS FlexCel - Open a xlsx generated by EPPlus - epplus

I have created a simple workbook with EPPlus in C# .NET Core (The file is XLSX).
I need to export this workbook to PDF.
I am trying to export using TMS FlexCel for .NET.
But, when the code try to export I get the error below:
FlexCel.Core.FlexCelCoreException: 'Invalid Cell: "#REF!"'
If I save the same workbook as XLS, the code works perfectlly.
Below is my code:
string file = #"D:\Test.xlsx";
string pdfFile = Path.ChangeExtension(file, ".pdf");
Excel.SaveAs(new FileInfo(file));
XlsFile xls = new XlsFile(false);
xls.Open(file);
FlexCelPdfExport pdf = new FlexCelPdfExport(xls, true);
pdf.Export(pdfFile);
Thanks

I found the problem.
The file generated by EPPlus is OpenXml format and the FlexCel doesn't recognize the format.

Related

Import annotations from one file to another using VBA exportAsFDF

I am trying to import annotations from one file to another using VBA through adobe Javascript object interface.
So I want to export the fdf file of the pdf, so I am using exportAsFDF method.
However, it is exporting an FDF file without the annotations, only linking to the main file, which is different from the fdf file exported from Adobe GUI.
Here is my code below. I am already considering including annotations as True, which is the last parameter in exportAsFDF.
So does anyone know what's wrong with the code below?
Sub importComments()
Set AcroApp = CreateObject("AcroExch.App")
Set compositeDocument = CreateObject("AcroExch.PDDoc")
compositeDocument.Open ("C:\Users\...\sample.pdf")
Set sourceJSObject = sourceDocument.GetJSObject()
Set compositeJSObject = compositeDocument.GetJSObject()
Path = "C:\Users\C:\Users\...\trials.fdf"
Debug.Print compositeJSObject.exportAsFDF(True, True, "", True, Path, True)
End Sub

Reading an .xltx file and Writing to .xlsx file with openpyxl

I've been struggling with this problem for a while and couldn't find a solution else where. I have several excel templates in xltx format that I want to read, then write a new xlsx file after filling in some cells.
Every time I run my code it creates a corrupted excel file. Using a preview extension in VS code I'm able to see that the values were correctly changed. When I read an xlsx file instead of an xltx it works fine. Does openpyxl just not allow what I am trying to do?
import openpyxl
import win32com.client
report = openpyxl.load_workbook("0100048-A5_R_11.xltx")
sheet = report["A5 form"]
search_arr = ["Test_Date"]
for r in range(2, sheet.max_row+1):
for c in range(3,sheet.max_column+1):
val = sheet.cell(r,c).value
if val != None and "$!" in str(val):
sheet.cell(r,c).value = 1
report.active = 1
report.save("output.xlsx")
Copied from the docs:
You can specify the attribute template=True, to save a workbook as a template:
wb = load_workbook('document.xlsx')
wb.template = True
wb.save('document_template.xltx')
or set this attribute to False (default), to save as a document:
wb = load_workbook('document_template.xltx')
wb.template = False
wb.save('document.xlsx', as_template=False)
Although the last line is from the latest docs, as_template is not a keyword argument for save!
This works instead:
wb.save('document.xlsx')

how to copy popup window text message and paste into Excel file using selenium

I want to copy popup window Text Message and paste that message into Excel file and then compare that data with Actual data. I am able to read the popup window text message and display on consol window, But how to paste that message into excel file
Selenium doesn't provide any functionality to deal with Excel documents, however assuming you're using Java you can read and write Excel files using Apache POI library
Workbook wb = new HSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
Sheet sheet = wb.createSheet("Sheet1");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue(createHelper.createRichTextString("Hello world"));
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
Hope it will help you.

how can I convert pdf file to word file using vb.net

I'm trying to develop a program which allows the user to convert a pdf file to a word file using vb.net.
Is there any good API for this ?
And, is it as easy as it looks like?
try this,
' Path of input PDF document
Dim filePath As String = "d:\\Source.pdf"
' Instantiate the Document object
Dim document As Aspose.Pdf.Document = New Aspose.Pdf.Document(filePath)
' Create DocSaveOptions object
Dim saveOptions As DocSaveOptions = New DocSaveOptions()
' Set the recognition mode as Flow
saveOptions.Mode = DocSaveOptions.RecognitionMode.Flow
' Set the Horizontal proximity as 2.5
saveOptions.RelativeHorizontalProximity = 2.5F
' Enable the value to recognize bullets during conversion process
saveOptions.RecognizeBullets = True
' save the resultnat DOC file
document.Save("d:\\Resultant.doc", saveOptions)

Trying to open a excel template and rename or save to new location

I get the following error message when I try the following:
Dim XL As New Microsoft.Office.Interop.Excel.Application
XL.Visible = True
XL.Workbooks.Open(XLTemplatePath)
XL.SaveWorkspace(XLSaveReportPath)
XL.Workbooks.Close()
XL.Workbooks.Open(XLSaveReportPath)
"Excel cannot open the file 'ContactReports.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."
What I would like to do is Open a excel file that is the XLTemplatePath and the either rename or save the file at the XLSaveReportPath and then use that renamed/saved file to fill the report out.
I am using Visual Studio 2008 in VB.NET
The saveworkspace method does not save the file. It save the workspace in the format xlw even though you are naming the file you are saving the workspace in as xls. When you try and open the document you are opening a worspace and you recieve the error.
To have this work correctly you need to get the workbook so you can sabe the workbook instead of the application.
Dim XL As New Microsoft.Office.Interop.Excel.Application
Dim XLWorkbook as new Microsoft.Office.Interop.Excel.Workbook
XL.Visible = True
XLWorkbook = XL.Workbooks.Open(XLTemplatePath)
XLWorkbook.SaveAs(XLSaveReportPath)
XL.Workbooks.Close()
XL.Workbooks.Open(XLSaveReportPath)
Should do the trick. Let us know if you have any problems.
Heare are the MSDN refrences for your review:
Application.SaveWorkspace Method
Workbook.SaveAs Method
I have used the following Visual Basic code to work with Microsoft Excel 2003. The key difference (other than Visual Basic 6 vs VB.Net) is that I use the SaveAs method of the Workbook object rather than the SaveWorkspace method.
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Visible = True
Set ExcelDoc = ExcelApp.Workbooks.Open(FileName:=XLTemplatePath, ReadOnly:=True)
ExcelDoc.SaveAs(FileName:=XLSaveReportPath)
ExcelDoc.Close(SaveChanges:=False)
ExcelApp.Workbooks.Open(FileName:=XLSaveReportPath)