How to use Labtalk in Origin(fit peaks in loop and export datas to .csv) - scripting

loop(n,3,5){
fitpeaks iy:=[Book1]Sheet1!(1,$(n)) np:=1 rd:=<new name:=$(n);
expExcel c:\Users\Book1.xls;
}
I'm trying to automate OriginPro using labtalk programming.
Code's purpose is to find peak and get fitted data worksheet as csv file
I keep failing to name the Workbook and sheets
anybody know
how to designate the new fitted data worksheet's Book?
I want to get the fitted data worksheet in one Workbook like
[Book1]Sheet3
[Book1]Sheet4

Related

How to open first sheet and write to the second column using openpyxl?

I'm using an existing excel sheet and the Zillow API to pull the square feet from each house in my neighborhood. I want to open an existing excel workbook, make the first worksheet active, and write the square feet in the second column.
I think the problem is it's not make the worksheet active to write the square feet into the second column. There's quite a bit of code underneath that works when I print to console. I'm trying to use a simple ws.write method but it doesn't recognize ws as a class.
def neighborhood_test():
location = "Address List Cypress Bend.xlsx"
wb_out = Workbook(location)
ws = wb_out.active
print(type(ws))
It should return a worksheet class but returns class 'NoneType' instead.
I figured out what I was doing wrong but now I need to learn how to iterate through it using other xlrd and Zillow API methods. This is the code you need to use an existing excel sheet.
def neighborhood_test():
location = "Address List Cypress Bend.xlsx"
wb_out = load_workbook(location)
worksheet = wb_out.active
print(worksheet.title)
This successfully prints out the first sheet which is Sheet1 for me.

How to reference a workbook from another excel instance

I believe my problem is rather simple: I have a workbook and I'm using it to get some data from another software (SAP). When I export the data from the software, it automatically opens a .xlsx file, then what I'd need to do is copy some of the data from this file, paste on my original workbook, and then close the file. The section of my code which is giving me an error is this one:
fileName = "temp1.xlsx"
Set wbBasis = Workbooks(fileName)
This happens because the "temp1.xlsx" file that was opened by the SAP software is in another instance of excel, so my code isn't able to find it.
What I need to know is basically this. How to properly reference this "temp1.xlsx" workbook on my original code so that I'm able to edit it, copy stuff from it, close it, etc.
I've found some similar topics to my problem, like the two I'm listing down here, but couldn't adapt the solutions to my situation, and that's why I'm posting this new one.
Having multiple excel instances launched, how can I get the Application Object for all of them?
Finding a workbook in one of multiple Excel instances
Thank you in advance.
You don't need multiple instances of Excel, and you don't need the Excel file to be open in order to get information from it, either with VBA, or even with regular "linked formulas".
For example:
=SUM([C:\yourPath\Filename.xlsx]SheetName!A1:C25)
...returns the sum of cells A1:C25 on a worksheet named Sheetname in an Excel file located at C:\yourPath\Filename.xlsx.
Or you can import all the data directly with Get External Data.
See:
MSDN : Create an external reference (link) to a cell range in another workbook
MSDN : Connect to another workbook
...for more information and examples, search Google for "get data from another Excel workbook".

Excel : Printing all workbook but with refreshing (recalculating) each tab before printing it

I am having some issues with printing an excel file i'm using.
The file is made of a mastersheet, and several sheets that contain individual reports (using data in the mastersheet).
The sheets are generated from a template by a macro, and are automatically named. The sheet name is referenced in the sheet, and I am using Index/match to pull the data I need from the mastersheet. So this means that the tabs need to be recalculated constantly when I switch between them (and there's a little piece of VBA code that does it perfectly).
My issue is that when I want to print the individual reporting sheets, they are all printed with the same data (because their contents are not refreshed individually before printing).
Is there any way of printing them without selecting them one by one and individually printing them each time ?
I thought about some macro/vba code that would copy paste the sheets as values in another workbook, and then printing this workbook, but I'm not sure if its the optimal or quickest way of doing things. I would appreciate it if someone could help me.
Thanks !
Here's a start for you
Sub S
Dim ws as worksheet
For each ws in worksheets
ws.calculate
'or call your recalc routine
ws.printout
next ws
end sub

Take a selection of Excel cells, store each in range to a variable, and print text to a script

I am trying to automate a script that I use for PowerShell. When I get a request, instead of editing the script line by line with required information, I would like to create an Excel spreadsheet, input the data required, and populate my script with those variables in the correct location.
From a high level view with limited programming experience, this does not seem overly complicated but I cannot figure it out.
I am able to do bits and pieces of what I am trying to accomplish, but not everything together. Below is step by step what I want to accomplish.
Input data into Cells B10 through B16
Store each cell into an individual variable
Hit the command button which will take the variables and print/overwrite a file already created.
I have a specific file path that I need to use.
Here is the code that I have already, that I see will copy the cells and open my PowerShell module.
Public Sub CommandButton1_Click()
Dim fileName As Variant
Dim Azure As Workbook
Dim wsSource As Worksheet
Set Azure = ActiveWorkbook
Set wsSource = ActiveSheet
'Copy range on original sheet
wsSource.Range("B10:B16").Copy
fileName = Shell("powershell_ise.exe ""c:\Azure\AZURE_1.ps1""", vbNormalFocus)
End Sub
I can see that the above code doesn't accomplish what I need to do. However, I can see that I can use the button, copy the cells, and open the required file.
What I need to do is take each cell and place at a certain spot in my script and overwrite the previous file.

openpyxl data_only gives only a none answer when storing a variable

So basically what I am trying to do is read in some input variables from an excel workbook and write them into some Output Model cells. Then I save the workbook to try to update the data in the Output Model. Since my Output Model cells are formulas I try to reload the workbook as a read data_only and then grab those cells and store them on a separate sheet. Then I save the workbook one more time.
The problem is the values I try to grab (LS, Sales, TPLH) in the data_only loaded workbook reads out as none instead of the values that I need. I eventually want to make this into a loop to iterate over a bunch of input variables, but I wanted to try it with just one set to begin with.
If anyone knows of a better way to do this or what I am doing wrong please let me know! I appreciate any and all feedback.
Here is my code:
from openpyxl import load_workbook
wb2 = load_workbook("Z:\\PythonFiles\\testexcel.xlsx")
sh2 = wb2.get_sheet_by_name("Output Model")
sh= wb2.get_sheet_by_name('OptimizationData')
ForeCast = sh.cell(row=3, column=2).value
sh2.cell(row=3, column=6).value=ForeCast
wb2.save("Z:\\PythonFiles\\testexcel.xlsx")
wb = load_workbook("Z:\\PythonFiles\\testexcel.xlsx", data_only =True)
sh3 = wb.get_sheet_by_name("Output Model")
sh4 = wb.get_sheet_by_name("OptimizationData")
LS=sh3.cell(row=11, column=3).value
Sales = sh3.cell(row=12, column=3).value
TPLH = sh3.cell(row=13, column=3).value
sh4.cell(row=3, column=7).value=LS
sh4.cell(row=3, column=8).value=Sales
sh4.cell(row=3, column=9).value=TPLH
wb.save("Z:\\PythonFiles\\testexcel.xlsx")
Openpyxl will never calculate the result of a formula. It is entirely dependent upon another application having done that. It also means that such values are stripped from a workbook when it is passed through openpyxl. This happens as soon as you save wb2. If you want to access those values then you need to open wb in data-only mode first.