how to copy popup window text message and paste into Excel file using selenium - 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.

Related

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')

TMS FlexCel - Open a xlsx generated by 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.

get the value from checked box in excel using Apache POI

I have these options (image link above) in my excel sheet in cells, E19, 20 and 21. How do I get the value of the box that is checked using Apache POI. I tried getBooleanValue(); , but it doesn't seem to work.
You have to use getBooleanCellValue() on the cell.
Here's a basic example, assuming the cell is A1 :
FileInputStream inputStream = new FileInputStream("test.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
XSSFSheet sheet = workbook.getSheetAt(0);
XSSFRow row = sheet.getRow(0);
XSSFCell cell = row.getCell(0);
cell.getBooleanCellValue();

How to stop a Word Document immediately when newly created

I have a VS2010 Vb.net program that creates a Word 2007 file.
My Normal.dot file is customised to give me a new Tab with Buttons in that do specific things via VBA in the Normal.dot program when those Buttons are pressed.
This all works fine, however, I now want to add some functionality whereas as soon as the new Word document is created, it edits a Task in Outlook.
I have edited the 2 "This Document" Procedures and you can see my Normal.Dot file in the attached Screenshot.
When I run my VB.Net program to create a brand new Word 2007 document, the program does NOT stop on either of the message boxes, it just continues and opens the Word document as before, my code is below, what am I doing wrong ?!?
'Open or Create Word document for Editing
myNewsLetter = myFolder + myLeague + "News" + mySession + ".doc"
If File.Exists(myNewsLetter) Then
'do nothing
Else
myTemplate = myTempFolder + "NL Skeleton.doc"
File.Copy(myTemplate, myNewsLetter)
Create_Blank_Newsletter()
End If
'Open Word Newsletter, or switch to it if it's already open
Dim myFileOpen As Boolean
myFileOpen = IsFileOpen(myNewsLetter)
If myFileOpen = False Then
MSDoc = MSWord.Documents.Open(myNewsLetter)
End If
MSWord.WindowState = Word.WdWindowState.wdWindowStateNormal
MSWord.Visible = True
MSWord.ActiveDocument.Bookmarks("\StartOfDoc").Select()
OK, sorted this, the full discussion can be found here ... http://www.vbaexpress.com/forum/showthread.php?p=286771#post286771
Basically, I'm not creating a NEW document, I am creating a new document via a Copy and then opening that existing document !!!

Reading excel attachment on itemAdded event

I'm trying to read excel file which is uploaded on itemadded event. I need to update meta data column of document library by reading uploaded excel sheet. But I get following error,
Here is my code,
SPItem item = properties.ListItem;
string workbookpath = "http://server/sites/dev/Published%20documents/Test.xlsx";
ApplicationClass excel = new ApplicationClass();
excel.Visible = false;
Workbook excelWorkBook = excel.Workbooks.Open(workbookpath, 0, true, 5, "", "", false, XlPlatform.xlWindows, "", true, false, 0, true, false, false);
Sheets sheets = excelWorkBook.Worksheets;
Worksheet worksheet = (Worksheet)sheets.get_Item(1);
Range range = worksheet.get_Range("A1", "A1");
item["Status"] = (string)range.Cells.Value2;
item.Update();
base.ItemAdded(properties);
For testing purpose I've hard coded the excel file path.
Take a look at this blog post. I think it will help
http://hristopavlov.wordpress.com/2008/05/14/uploading-a-file-event-receivers-the-file-has-been-modified-by/
I think the problem that you document is in checked out state because you have open it from excel app, so you need to do following:
close excel app
Check in document back to save chages or undo check out (use item.CheckIn() or item.UndoCheckOut())
after this you should be able to update item properties