Financial Applications Using Excel Add-in Development in C/C++Second Edition phần 10

Trong thực tế, điều này là quá mức cần thiết. Một cách tiếp cận hiệu quả hơn sẽ được sử dụng xlcOnRecalc để nắm bắt những sự kiện tính toán lại các API C có thể xử lý và thiết lập một biến toàn cầu sau đó, hoặc Ví dụ Add-ins và các ứng dụng tài chính | Example Add-ins and Financial Applications 497 day - m_days month - 1 return if is_leap_year y if m_days FEB --day day 29 month FEB return for month DEC month if m_days month day break day - m_days month - 1 The above code assumes that the serial day-count is that which Excel stores when using its default 1900 date If your application is critically dependent on dates you should check the status of this setting and convert all incoming and returned dates. The following code samples show how to do this. Note that the exported worksheet function accepts and returns dates as 32-bit integers type J. Note also that the state of Excel will not change during a single call to a function but would need to be checked on every call to be super-safe. In practice this is overkill. A more efficient approach would be to use xlcOnRecalc to capture those recalculation events that the C API can handle and set a global variable then or use the more specific VBA recalculation event traps to call a function in the XLL that resets this. bool excel_using_1904_system void cpp_xloper Using1904 initialised to xltypeNil cpp_xloper Arg 20 initialised to xltypeInt xlfGetDocument 1 Arg return define DAYS_1900_TO_1904 1462 1-Jan-1904 in 1900 system int __stdcall worksheet_date_fn int input_date bool using_1904 excel_using_1904_system if using_1904 input_date DAYS_1900_TO_1904 Do something with the date int result some_date_fn input_date 6 Excel mistakenly thinks that 1900 was a leap year and therefore the first correct interpretation of a date under this system is 1-Mar-1900 which equates to the value 61. 498 Excel Add-in Development in C C if using_1904 result - DAYS_1900_TO_1904 return result The following is a slightly quicker implementation of excel_using_19 04_system that uses xlopers directly as creator and destructor calls and overloaded operator calls are not required. An optimising compiler might produce code this efficient of course. You might .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
182    215    1    03-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.