File Exchange
Try Origin for Free
The Origin Forum
Home
|
Profile
|
Register
|
Active Topics
|
Members
|
Search
|
FAQ
|
Send File to Tech support
All Forums
Origin Forum for Programming
Forum for Python
Operation failed: Book/Sheet type can only be 'w'(
Note:
Only the poster of this message, and the Moderator can edit the message.
Screensize:
640 x 480
800 x 600
1024 x 768
1280 x 1024
UserName:
Password:
Anti-Spam Code:
Format Mode:
Basic
Help
Prompt
Format:
Font
Andale Mono
Arial
Arial Black
Book Antiqua
Century Gothic
Comic Sans MS
Courier New
Georgia
Impact
Lucida Console
Script MT Bold
Stencil
Tahoma
Times New Roman
Trebuchet MS
Verdana
Size
1
2
3
4
5
6
Color
Black
Red
Yellow
Pink
Green
Orange
Purple
Blue
Beige
Brown
Teal
Navy
Maroon
LimeGreen
Forum:
Forum for Python
Subject:
Message:
* HTML is OFF
*
Forum Code
is ON
Smilies
I am using Origin Lab Pro 2025. Using the following .py code to copy data from a book/sheet/col to append in another book/sheet/col. import originpro as op import numpy as np def copy_append_data(): try: # Set the active window to avoid context issues op.set_show(True) # Get source data - using absolute references src_book = op.find_book('Book1') if src_book is None: raise Exception("Source Book1 not found. Please ensure it exists and is open.") # Explicitly get the first sheet if name doesn't work src_sheet = src_book[0] if src_book.sheets_count >= 1 else None if src_sheet is None: raise Exception("No sheets found in Book1") # Get source data as numpy arrays colA = np.array(src_sheet.to_list(0), dtype=float) colB = np.array(src_sheet.to_list(1), dtype=float) if len(colA) == 0 or len(colB) == 0: raise Exception("No data found in source columns") # Handle destination book - critical section dest_book = op.find_book('Book3') if dest_book is None: # Create new book with explicit worksheet type dest_book = op.new_book('w') dest_book.lname = 'Book3' # Set name after creation # Get or create destination sheet if dest_book.sheets_count == 0: dest_sheet = dest_book.add_sheet('Sheet1') else: dest_sheet = dest_book[0] # Get first sheet # Get existing destination data dest_colA = [] dest_colB = [] try: dest_colA = dest_sheet.to_list(0) dest_colB = dest_sheet.to_list(1) except: pass # Columns might be empty # Calculate starting row for append start_row = len(dest_colA) if dest_colA else 0 # Prepare data for insertion new_data = np.column_stack((colA, colB)) # Insert data in one operation (more efficient) if start_row == 0: # First time writing to empty sheet dest_sheet.from_np(new_data, False) else: # Append to existing data combined = np.vstack((np.column_stack((dest_colA, dest_colB)), new_data)) dest_sheet.from_np(combined, False) # Set column names dest_sheet.cols = 2 # Ensure we have 2 columns dest_sheet.set_label(0, "A") dest_sheet.set_label(1, "B") print(f"Success! Appended {len(colA)} rows to Book3/Sheet1") return True except Exception as e: print(f"Operation failed: {str(e)}") print("Troubleshooting tips:") print("1. Ensure Book1 exists and has data in columns A-B") print("2. Close and reopen Origin if you've recently deleted Book3") print("3. Try running the script with Origin in focus") return False # Execute if __name__ == "__main__": copy_append_data() While executing, I am getting the following error - Operation failed: Book/Sheet type can only be 'w'(Worksheet) or 'm'(Matrix) Troubleshooting tips: 1. Ensure Book1 exists and has data in columns A-B 2. Close and reopen Origin if you've recently deleted Book3 3. Try running the script with Origin in focus I followed the suggestions but still getting same error. Please, help to solve the problem ? Bipul
Check here to subscribe to this topic.
The Origin Forum
© 2020 Originlab Corporation
Snitz Forums 2000