惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
Cloudbric
Cloudbric
V
Visual Studio Blog
L
LangChain Blog
A
About on SuperTechFans
B
Blog
T
Tenable Blog
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
博客园 - 三生石上(FineUI控件)
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Palo Alto Networks Blog
U
Unit 42
WordPress大学
WordPress大学
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News and Events Feed by Topic
T
Threat Research - Cisco Blogs
C
Check Point Blog
Security Latest
Security Latest
M
MIT News - Artificial intelligence
Application and Cybersecurity Blog
Application and Cybersecurity Blog
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
NISL@THU
NISL@THU
Forbes - Security
Forbes - Security
S
Securelist
Security Archives - TechRepublic
Security Archives - TechRepublic
Hugging Face - Blog
Hugging Face - Blog
aimingoo的专栏
aimingoo的专栏
Latest news
Latest news
GbyAI
GbyAI
T
Troy Hunt's Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LINUX DO - 热门话题
V2EX - 技术
V2EX - 技术
小众软件
小众软件
Google DeepMind News
Google DeepMind News
K
Kaspersky official blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
O
OpenAI News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
Netflix TechBlog - Medium
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed

博客园 - 尘梦

calude code 2.188 根据cli.map还原 centos6 安装gcc 多版本 自定义编译bulma 神通mysql模式转 mysql ai数学书籍 chromedriver 网络安全渗透测试写法 编译php需要的扩展 python 合并同列数据 组合 新的excel vue table 表格记录选中 linux wktohtmlpdf 结合/tmp路径 无法创建问题 c语言开发 php扩展 sm4 macos php 如何链接神通数据库aci layui table tr a标签倒计时 操作 刷新以后继续倒计时 世界级地图数据处理 及 联动效果 php 结合pcntl_fork导出excel数据 使用 python 部署chatglm2b macos 下连接php 人大金仓pdo_kdb问题 php curl 多次发送
使用c# 开发 php的com组件
尘梦 · 2024-03-19 · via 博客园 - 尘梦

使用c# 开发 php的com组件 读取word内容(表单域、书签内容)

注意问题:
1、查看php版本(64、32)
2、查看系统版本
3、按照系统对应的版本注册组件

这里环境是64 .net 4.0

所以路径是:C:\Windows\Microsoft.NET \Framework64(64位Framework框架)\ net版本 \ RegAsm.exe

php传递给c# 编码问题 (死活不对,使用bstr、各种编码转换都不行,最后使用base64)

vs2017 =》需要设置 项目-属性-生成-为Com互操作
vs2017 => 应用程序-》程序集信息-》选中com

具体代码如下:
com组件是以接口形式开放给php调用的所以这块要注意


[ComVisible(true)]
    [Guid("自己生成")]
    public interface IMyComInterface
    {
        Document OpenDoc(string fileName,bool readOnly=false);
        string GetFormFields(string fieldName, int section=0);
        string GetTableFields(int tableIndex, int rowIndex, int colIndex, int section = 0);
        string getBookmarkText(string sBookmark);
        string getBookmarkText1(string sBookmark);
        void strings(string text);
        string GetTableFormFields(int iTable, int iRow, int iCol, int iSection = 0, object sFieldName = null);
        int getSectionTableRowsNum(int section, int tableIndex);
        void Closes();
        int getSectionTableNum(int section);

    }


[ComVisible(true)]
    [Guid("自己生成")]
    [ClassInterface(ClassInterfaceType.None)]
    public class MyComClass : IMyComInterface
    {
实现的代码
    }


几个小问题 处理编码 

 public static string getBase64(string base64String="")
        {
            if (!IsBase64String(base64String)) {

                return base64String;
            }

            byte[] data = Convert.FromBase64String(base64String);

            string originalString = Encoding.UTF8.GetString(data);

            return originalString;
        }

 public static string RemoveInvisibleCharacters(string input)
        {
           
            // 控制字符:\p{C}
            // 格式字符:\p{Cf}
            // 私用使用区:\p{Co}
            // 不可见字符:\p{Cs}
            string pattern = @"\p{C}+|\p{Cf}+|\p{Co}+|\p{Cs}+";

            // 使用正则表达式移除不可见字符
            return Regex.Replace(input, pattern, string.Empty);
        }

 //表单域提取
static string Escape(string str)
        {
            //Regex regex = new Regex("(\\\\)*\\\\?'");
            //str = regex.Replace(str, "\\'");
            str = Regex.Replace(str, @"FORMTEXT|[\x00-\x1F\x7F]", "").Trim();
            return str;
        }