zoukankan      html  css  js  c++  java
  • 将表格粘贴为Word可识别的格式

    // Open the clipboard...
    if(!OpenClipboard()) {
       ::MessageBox(NULL, "Cannot open clipboard.", "Error", 0x10010);
       return;
    }

    // Get Clipboard format id for RTF.
    UINT cf = RegisterClipboardFormat("Rich Text Format");

    // Empty anything already there...
    EmptyClipboard();

    // *** This section of code adds the RTF table to the clipboard
    // *** RTF-Data to put on clipboard
    const char *text =
       "{\\rtf1\\par "
       "\\trowd \\trgaph30\\trleft-30\\trrh262\\cellx980\\cellx1991\\cellx3001"
       "\\intbl \\qr \\f0\\fs20 \\cf 1\\cell \\qr 2\\cell\\qr 3\\cell \\intbl \\row"
       "\\trowd \\trgaph30\\trleft-30\\trrh262\\cellx980\\cellx1991\\cellx3001"
       "\\intbl \\qr \\f0\\fs20 \\cf 4\\cell \\qr 5\\cell\\qr 6\\cell \\intbl \\row}";

    // Allocate global memory for transfer...
    HGLOBAL hText = GlobalAlloc(GMEM_MOVEABLE |GMEM_DDESHARE, strlen(text)+4);

    // Put our string in the global memory...
    char *ptr = (char *)GlobalLock(hText);
    strcpy(ptr, text);
    GlobalUnlock(hText);

    // Put data on the clipboard!
    ::SetClipboardData(cf, hText);

    // Free memory...
    GlobalFree(hText);

    // *** Now, add a version of the same data as tab-delimited text...
    // *** This will be used by Microsoft Excel
    char *text2 = "1\t2\t3\n4\t5\t6";

    // Allocate global memory for transfer...
    hText = GlobalAlloc(GMEM_MOVEABLE |GMEM_DDESHARE, strlen(text2)+4);

    // Put our string in the global memory...
    ptr = (char *)GlobalLock(hText);
    strcpy(ptr, text2);
    GlobalUnlock(hText);

    // Put data on the clipboard as CF_TEXT
    ::SetClipboardData(CF_TEXT, hText);

    // Free memory...
    GlobalFree(hText);


    // Close clipboard...
    CloseClipboard();
  • 相关阅读:
    2019我学的东西
    jmeter之 java请求
    zookeeper简介和一些常用功能
    python 常见的一些高阶函数
    Jmeter之远程运行
    vue-cli eslint配置
    vue——element-ui项目中用如何点击导航菜单进行当前页面的router切换
    Vue 实现复制到粘贴板功能
    vscode 常用插件
    vue cli3中使用less
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/619012.html
Copyright © 2011-2022 走看看