Copy from https://libxlsxwriter.github.io/getting_started.html
1
sudo apt-get install libxslt-dev
2.
git clone https://github.com/jmcnamara/libxlsxwriter.git
3.
cd libxlsxwriter make
4.
cd cmake # Or another sub-directory. cmake .. cmake --build .
5.
sudo cp libxlsxwriter.so.5 /usr/lib/libxlsxwriter.so.5
#pragma once #include <chrono> #include <condition_variable> #include <ctime> #include <curl/curl.h> #include <curl/easy.h> #include <fstream> #include <functional> #include <future> #include <iostream> #include <iomanip> #include <map> #include <memory> #include <mutex> #include <random> #include <stdio.h> #include <string> #include <uuid/uuid.h> #include <vector> #include "xlsxwriter.h" std::string get_time_now(bool is_exact = false) { std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now(); time_t raw_time = std::chrono::high_resolution_clock::to_time_t(now); struct tm tm_info = *localtime(&raw_time); std::stringstream ss; ss << std::put_time(&tm_info, "%Y%m%d%H%M%S"); if (is_exact) { std::chrono::seconds seconds = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()); std::chrono::milliseconds mills = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()); std::chrono::microseconds micros = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()); std::chrono::nanoseconds nanos = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()); std::uint64_t mills_count = mills.count() - seconds.count() * 1000; std::uint64_t micros_count = micros.count() - mills.count() * 1000; std::uint64_t nanos_count = nanos.count() - micros.count() * 1000; ss << "_" << std::setw(3) << std::setfill('0') << std::to_string(mills_count) << std::setw(3) << std::setfill('0') << std::to_string(micros_count) << std::setw(3) << std::setfill('0') << std::to_string(nanos_count); } return ss.str(); } char *uuid_value = (char *)malloc(40); char *get_uuid_value() { uuid_t new_uuid; uuid_generate(new_uuid); uuid_unparse(new_uuid, uuid_value); return uuid_value; } void xlsxwriter_excel(const int &len) { lxw_workbook *workbook = workbook_new("hello_world2.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); worksheet_set_column(worksheet,0,0,50,NULL); // write header worksheet_write_string(worksheet, 0, 0, "Header", NULL); worksheet_write_string(worksheet, 0, 1, "Number", NULL); for(int row=1;row<=len;row++) { worksheet_write_string(worksheet,row,0,get_uuid_value(),NULL); worksheet_write_number(worksheet,row,1,row,NULL); } workbook_close(workbook); std::cout<<get_time_now(true)<<",finish in "<<__FUNCTION__<<std::endl; } int main(int agrs,char **argv) { xlsxwriter_excel(atoi(argv[1])); return 0; }
6.Compile
g++ -std=c++2a -I. *.cpp -o h1 -luuid -lpthread -lxlsxwriter
7.Run
./h1 1000000
标签:std,count,now,chrono,libxlsx,time,install,Ubuntu,include From: https://www.cnblogs.com/Fred1987/p/17442487.html