AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 06.09.2012, 18:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
axblog4u: Tip: COMVariantType for Real values in Dynamics AX
Источник: http://axblog4u.wordpress.com/2012/0...n-dynamics-ax/
==============

<span style="font-family:'Trebuchet MS';color:#204063;font-size:10pt;">
Case Study: Reading cell content from excel template for COM variant type VT_R4 or VT_R8 is always little tricky.

Observation: Reading real value can be done in following ways
1) num2Str0(_variant.double(), 0);
2) num2str(_variant.double(), 0, numOfDec(_variant.double()), 1, 0);

Here is the output which is generated where the first function value is always a round-off value compared with the second function which returns the exact content with correct scale and precision.

COMVariantType Functions output for Real values.





/* Build excel template as following and specify the path @ excel=======================================Column Integer Real =======================================Rows(1) 123 60.9756097560976Rows(2) 234 5.69105691056911=======================================*/static void SR_VariantType(Filename excel = @'C:\Projects\Data.xlsx'){ int rows; int columns; COMVariant variant; SysExcelCells sysExcelCells; SysExcelWorkbook sysExcelWorkbook; SysExcelWorkbooks sysExcelWorkbooks; SysExcelWorksheet sysExcelWorksheet; SysExcelWorksheets sysExcelWorksheets; SysExcelApplication sysExcelApplication; str variant2Str(COMVariant _variant) { str valueStr; ; switch(_variant.variantType()) { case COMVariantType::VT_EMPTY : valueStr = ''; break; case COMVariantType::VT_BSTR : valueStr = _variant.bStr(); break; case COMVariantType::VT_R4 : case COMVariantType::VT_R8 : if(_variant.double()) { valueStr = strFmt("@SYS311964", num2Str0(_variant.double(), 0), num2str(_variant.double(), 0, numOfDec(_variant.double()), 1, 0)); } break; default : throw error(strfmt("@SYS26908", _variant.variantType())); } return valueStr; } ; sysExcelApplication = SysExcelApplication::construct(); sysExcelWorkbooks = sysExcelApplication.workbooks(); try { sysExcelWorkbooks.open(excel, false /*Update links*/, true /*Read only*/); } catch (Exception::Error) { throw error(strFmt("@SYS76826", excel)); } sysExcelWorkbook = sysExcelWorkbooks.item(1); sysExcelWorksheets = sysExcelWorkbook.worksheets(); // Only considering Sheet 1 sysExcelWorksheet = sysExcelWorksheets.itemFromNum(1); sysExcelCells = sysExcelWorksheet.cells(); // Since in first row there will be field names. for ( rows = 2; rows
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 10 Blog bot Dynamics CRM: Blogs 0 17.08.2012 03:27
emeadaxsupport: New Content for Microsoft Dynamics AX 2012 : October 2011 Blog bot DAX Blogs 0 27.10.2011 17:11
dynamics-ax: Interview with Microsoft's Lachlan Cash on his new role, AX 2012 and more Blog bot DAX Blogs 6 22.04.2011 14:55
axinthefield: Dynamics AX Event IDs Blog bot DAX Blogs 0 01.03.2011 22:11
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 00:10.