The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Python
 Date format using Set column values
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

belebele

4 Posts

Posted - 10/29/2021 :  09:32:35 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello,

I use a data connector to import excel files containing several sheets. I want to copy two specific cells (B2 and C2 in the example below) of one of the sheets into a new worksheet where I gather all my results. However, when I copy those specific cells into the new worksheet, there is no value displayed "--". The problem comes obviously from the format of the imported cells.

Therefore, I would like to change the format of the imported cells automatically. In order to so, I have implemented a python code in "Set columns values". When my data is a number, it works well as you can see below. In the screenshot, I have simplified the structure of the sheet to make the issue clearer: (t refers to col(D) and tim to col(B)). The cell D1 contains now the value of B2 in the right format.



I am now trying to write another function to do the same with the date format in col(C) but I don't understand well what should I use in this case instead of "float". I have tried the following code but it doesn't work. t refers to col(E) and tim to col(C).



Do you have any suggestion to make this work?

I don't want to change the format of the cell directly in the excel file as I have a huge amounts of excel files to treat. Also, I am using a data connector to import those excel files quickly (they all have the same structure).

Thanks a lot for your help,
Greg

YimingChen

1621 Posts

Posted - 10/29/2021 :  11:19:04 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The date/time system in Origin is based on the astronomical Julian Day, so basically it is just a float number behind each date value. So in coding you simply treat it as number. See the figure below:
https://www.originlab.com/doc/Origin-Help/DateTime-in-Origin#Origin.27s_Mathematical_System_for_Date_and_Time



James
Go to Top of Page

belebele

4 Posts

Posted - 11/01/2021 :  10:51:01 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks James for your reply.

I tried your code but I got the following error:



Maybe the format of my cells are slightly different from the one in your trial? My values (date and numbers) are left-aligned after importing them.
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 11/01/2021 :  12:53:01 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Left aligned means the column is holding text, not numeric, so you need to first fix how you put values into the worksheet.

CP
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000