-2

I receive an Excel file via HttpRequest (not the point) and pass it to the ExecuteStreamCommand in order to get the value of a specific cell (via Python). The problem is that I don't know how to get exactly excel from sys.stdin in order to get the value through pandas or openpyxl.

 import sys
 print (type (sys.stdin))

In such a construction, the type <class '_io.TextIOWrapper'>

 import sys
 for line in sys.stdin:
     print (type (line))

In this construction, the type <class 'str'> (387 such lines in the output file)

I'm just starting to understand this topic, I started reading articles on python a couple of days ago, on nifi a couple of weeks ago

2 Answers2

0

Without knowing what your data looks like and what you're actually trying to achieve, it's hard to be specific.

This blog post talks about working on stdin with ExecuteStreamCommand & python https://mikethomsen.github.io/posts/2019/02/09/using-python-to-process-data-from-apache-nifi/

This question talks about reading xlsx from stdin with Python & pandas using pandas read_excel to read from stdin

I get the feeling it's probably more complex than it's worth to do it this way.

As an alternative, you could write the Excel sheet down to a file, and then pass the file location to a script to pick up e.g.

Http -> PutFile -> ExecuteProcess or ExecuteStreamCommand (file location as a paramter) -> rest of your flow

Meaning you don't have to worry about handling stdin as you're just working with files

Sdairs
  • 1,912
  • 1
  • 13
  • 13
0
import sys
import pandas as pd
import io
bt = io.BytesIO(sys.stdin.buffer.read())
sheet = pd.read_excel(bt, "SheetName1", header=None) 
res = sheet.at[1,2] #Cell 'C2'
print(res)

Through trial and error, the answer was found. This piece of code is pulling the value of a specific cell from excel(sys.stdin)