question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BDP formula not working with write_formula

See original GitHub issue

Hi,

I am using XlsxWriter to do write a BDP formula to a cell in Excel but it appears to do causes errors and outputs 0.0, as well as presenting a series of errors when opening the outputted excel file.


import xlsxwriter

orders_file =  r'Q:\.....'
date_extension = str(date) + '.xlsx'
writer = pd.ExcelWriter(orders_file+date_extension, engine = 'xlsxwriter')
df.to_excel(writer, sheet_name='Loans', index=False,startrow=1,startcol = 3, header=True)
loans_sheet = writer.sheets['Loans']    
worksheet.write_formula('B3', "=BDP(LEFT(C3,LEN(C3)-1)&' Corp', 'Issuer')")

workbook.close()

I’ve deleted all other information, and the Loans tab has the necessary info written to it before I try to put the formula there. Deleting the other info and saving it again seems to get rid of these errors but the value is still 0.0 This is the log file of errors that comes up :

<?xml version="1.0" encoding="UTF-8" standalone="true"?>

-<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">

<logFileName>error079040_01.xml</logFileName>

Errors were detected in file 'Q:\..................attribution2020-10-16.xlsx'

-<removedRecords>

<removedRecord>Removed Records: Formula from /xl

/worksheets/sheet4.xml part</removedRecord>

</removedRecords> </recoveryLog>

image github (1).xlsx

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jmcnamaracommented, Oct 19, 2020

I downloaded what I just uploaded and I do see a formula and an output from the BBG formula.

Apologies. I mistook the first and second files.

You can try the following. It loads but doesn’t calculate anything for me, since I don’t have the Bloomberg plugin. Note the _xll. prefix and that it should probably be an array formula. Also, the formula should have double quotes not single quotes:

from xlsxwriter.workbook import Workbook
    
workbook = Workbook('test.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write_array_formula('B4', '_xll.BDP(LEFT(C3,LEN(C3)-1)&" Corp", "Issuer")')

workbook.close()
0reactions
jmcnamaracommented, Oct 20, 2020

Good stuff. Thanks for sending the file. I’ll up date the StackOverflow question.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code to write formula with a cell reference - Mr. Excel
I am assuming you have tried using cell referernce instead of the date typed out and it didn't work. Code: =BDH("CL1 Comdty","PX_LAST",A1,A2,"Dir=V ...
Read more >
Formulas for collecting Bloomberg Data in Excel
BDP (Bloomberg data point): returns data to a single cell within Excel. It contains only one ticker and one field. Formula Syntax: =BDP...
Read more >
Q. Help! I got an error trying to download data ... - Ask a Librarian
#N/A Requesting Data - The #N/A Requesting Data message is the initial value that is placed in a cell when the formula (BDP,...
Read more >
vba to write formula with dynamic cell reference - Stack Overflow
You can make Cname variable dynamic if you like: CName = Range("F3").Address ActiveCell.Formula = "=BDP(" & CName & Chr(34) & " cusip" ...
Read more >
Troubleshooting Bloomberg Excel Integration
These instructions are for addressing issues using the Bloomberg ... If you open Excel and do not see a 'Bloomberg' tab or notice...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found