|
楼主 |
发表于 2015-11-28 16:30
|
显示全部楼层
顺便帖上类库代码:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Runtime.InteropServices;
- using Microsoft.Win32;
- using Microsoft.Office.Interop.Excel;
- namespace ExcelFunc
- {
- [Guid("56f8f4f7-8123-446a-a197-85c173c0284f")]
- [ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
- public class Class1
- {
- #region COM Related
- [ComRegisterFunction]
- public static void RegisterFunction(Type type)
- {
- Registry.ClassesRoot.CreateSubKey(GetSubKeyName(type, "Programmable"));
- var key = Registry.ClassesRoot.OpenSubKey(GetSubKeyName(type, "InprocServer32"), true);
- key.SetValue("", Environment.SystemDirectory + @"\mscoree.dll", RegistryValueKind.String);
- }
- [ComUnregisterFunction]
- public static void UnregisterFunction(Type type)
- {
- Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(type, "Programmable"), false);
- }
- private static string GetSubKeyName(Type type, string subKeyName)
- {
- var s = new System.Text.StringBuilder();
- s.Append(@"CLSID\{");
- s.Append(type.GUID.ToString().ToUpper());
- s.Append(@"}");
- s.Append(subKeyName);
- return s.ToString();
- }
- #endregion
- public string MyConcate(params Object[] values)
- {
- string iStr = "";
- Range iRng;
- for (int iStep = 0; iStep < values.Length; iStep++)
- {
- if (values[iStep].ToString() == "System.__ComObject")
- {
- iRng = (Range)values[iStep];
- if (iRng.Count > 1)
- {
- foreach (Range cRng in iRng)
- {
- iStr += Convert.ToString(cRng.Value);
- }
- }
- else
- {
- iStr += Convert.ToString(iRng.Value);
- }
- }
- else
- {
- iStr += values[iStep].ToString();
- }
- }
- return iStr;
- }
- }
- }
复制代码 |
|