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 Origin C
 Excel date formatting
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

couturier

France
291 Posts

Posted - 08/13/2020 :  11:20:46 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 2020b
Operating System:win10 64

Hi,

I'm importing an excel file with wks.ImportExcel().
It is quite fast and I can choose which sheet to import with og_get_excel_sheet_names()

However, I'm facing an issue with dates in cells
For example, 07/08/1988 (formatted as dd/mm/yyyy) is imported as 32362, which is not a julian value

If I import manually, it is shown correctly (but displays formatted as date, even if column format is numeric which is strange. I remember posting something about this but couldnt find)

How can I get the correct value ?

Thanx

couturier

France
291 Posts

Posted - 08/13/2020 :  11:28:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
OK, I could find the solution here: https://www.originlab.com/doc/Quick-Help/Date_Conversion_Origin_Excel

What a mess !!
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 08/15/2020 :  5:01:39 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I tested the following code in 2020b with a file I made with a column with date, and first tow as long name, and it imported correctly by setting column as date

#include <oExtFile.h>
void impxls(string strFile, bool bHeading = true, int nSheet = 0, bool bCellStyles = false)
{
	vector<string> vsSheets;
	int nn = get_excel_sheet_names(strFile, &vsSheets);
	if(nn <= 0) {
		out_str("not a valid Excel file");
		return;
	}
	Worksheet wks = Project.ActiveLayer();

	ExcelImportOptions stR;
	stR.xlsctrl.m_dwRXC = RXC_RESET_FORMAT | RXC_VALUE | RXC_VALUE_FORMAT | RXC_AUTO_RENAME_SHEET;
	if(bCellStyles)
		stR.xlsctrl.m_dwRXC |= RXC_STYLE;

	if(bHeading) {
		stR.header.SubHeaderLines = -1;
		stR.header.LongName = 1;
	}
	int nC2=-1;//to receive output actual last column
	
	//destination columns
	stR.xlsctrl.m_nStartColIndex = 0;
	stR.xlsctrl.m_pnLastColIndex = &nC2;

	int nErr = wks.ImportExcel(strFile, nSheet, &stR, true);
	if(nErr != 0)
		out_int("failed: ", nErr);
}


LT to call it

dlgfile g:=*.xlsx;impxls fname$;


CP
Go to Top of Page

couturier

France
291 Posts

Posted - 08/17/2020 :  02:36:19 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
What a mess !!

To make things clear: this comment applies to Excel, not Origin

Anyway, thanks for the code example. I couldn't find any documentation about ExcelImportOptions, so I had just used RXC_VALUE.
The function works perfect
Go to Top of Page

YimingChen

1618 Posts

Posted - 08/18/2020 :  09:27:10 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you for bringing this up. the sample code of the following page has been updated:
https://www.originlab.com/doc/OriginC/ref/Datasheet-ImportExcel

James
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