Author |
Topic |
|
Clairekun
Germany
175 Posts |
Posted - 07/21/2020 : 9:11:37 PM
|
Origin Ver. and Service Release (Select Help-->About Origin): 2018b Operating System: Windows 10
Hello,
I was wondering whether it was possible to populate a column with worksheet comments.
If I try %(1,@WMn)=; in a script window, the nth comment line is displayed; however, writing %(1,@WM) under "Set column values" will not fill each cell with its corresponding worksheet comment.
Is this achievable? How?
Thank you. |
|
cpyang
USA
1406 Posts |
Posted - 07/21/2020 : 9:59:58 PM
|
You can access the worksheet comments by using the following LTlayer.comments$
So you just need to write code in Before Formula script to process it. Using Python, it will be very simple, in the current beta version of Origin, then add the following Python function in labtalk.py in UFF,
def wcm(a)->list:
return a.splitlines()
Then in the column formula,
py.wcm(layer.comments$)
CP
|
|
|
Clairekun
Germany
175 Posts |
Posted - 07/22/2020 : 08:04:24 AM
|
Ok, let me try to understand. Please know I have never used Python before, so excuse my ignorance.
Do I forcefully need Origin last beta version? Although you stated this, Origin help reads that the software allows Python since version 2015 (please see here: https://www.originlab.com/doc/LabTalk/guide/work-with-python)
What I did is:
1. Create and save a function called WksComments.py in UFF with the code you provided. 2. Create a new column and select "Set column values" 3. Under "Before Formula scripts": run -pyf "WksComments.py" (as advised here: https://www.originlab.com/doc/LabTalk/ref/Run-cmd#-pyf.3B_Execute_Python_File)
4. Formula: py.wcm(layer.comments$) An error shows: quote: Mismatch double quote: py.wcm(layer.comments$) Failed to create operation for Book1_A@7 due to error in Set Column Value scripts
Is this because of version incompatibility or am I misunderstanding what you said? If it is the latter, I am afraid I will need a "step by step for dummies" explanation.
Apparently, looking into it a bit further, I might need to install Python externally. It is needed to install packages (although I don't know what that means), so this might be extrapolated to my situation.
Thanks,
Claire. |
|
|
cpyang
USA
1406 Posts |
|
Clairekun
Germany
175 Posts |
Posted - 07/22/2020 : 4:32:08 PM
|
Initially, I had imported the data to paste filename into worksheet comments to include them in a cell value, somehow. Since my version doesn't allow this, I had to think of a Labtalk workaround:
- Paste filename into column comments, instead, when importing. - Create a column whose cell values are the adjacent column comment. - Delete all column comments. - Delete filename from all rows except the first.
The last 2 steps are for further convenience, since I need to merge worksheets afterwards.
dlgfile multi:=1 group:=*.txt;
impasc fname$
Options.FirstMode:=0 //Import first dataset in workbook: replace existing worksheet
Options.Mode:=4 //Import 2nd to nth workbook to new sheets
Options.Sparklines:=2 //Sparklines if there are over 50 data cells
Options.Headers.CountHeaderLines:=1 //Confirm there are headers in the source data sets
Options.Headers.MainHeaderLines:=0 //Specify number of headers
Options.Headers.SubHeaderLines:=1 //Specify number of subheaders
Options.Headers.LongName:=1 //Set 1st subheader as long name
Options.Names.AutoNames:=0 //Do not rename workbooks automatically
Options.Names.FNameToColComm:=1 //Use file names in column comments
Options.Names.FNameToSht:=1 //Use file names to rename worksheets
Options.Names.FNameToBk:=0 //Do not fill comments with file names
Options.Names.FPathToComm:=0 //Do not fill comments with file path
Options.FileStruct.NumSep:=1 //Decimals are after a dot (90.25). For 90,25 write 1 instead
Options.FileStruct.Delimiter:=3;
doc -ef LW { //For all worksheets in folder
wks.col=1; //Activate Column 1
wks.insert(Smp); //Insert new column before Column 1
col(A)[L]$ = "Sample"; //New column Long Name
csetvalue col:=col(A) formula:="FnameFromCol$" s:="string FnameFromCol$ = Col(B)[C]$" r:=none; //Set adjacent column's comments as new column's cell values
wks.deleteRows(2,300); //Delete all cell values except first one //Is there any way to specify rows 2 to end? Could not find any. wks.nrows does not allow to set less than 15.
for (int nn = 2; nn <= wks.ncols; nn++) //For second column onwards
{
wcol(nn)[C]$=""; //Delete comments (undo impasc Options.Names.FNameToColComm:=1)
}
}
And that did the trick. A bit more complicated that I would have wanted, but it seems to work.
Thank you for your help. |
|
|
|
Topic |
|
|
|