在EXCEL FILE 裝一個木馬程式將相關之unicode encode 成 ASC 128~255之類, 讀入後再descode. 雖然好笨但可以讀中文同特殊碼。
![]()
>='Text ='9'Text='~'>'' then
if ((StrToInt(S_Char) > 255) or (i=1)) then
begin
Convert_Text:=S_Char Convert_Text;
S_state:=0;
end;
end;
end; end; Result:=Convert_Text;
end; function VBOpenExcelObj(xl_FileName:string;show:Boolean): Boolean;
var
Unknown: IUnknown;
Res: HResult;
begin
try
VBAppWasRunning := False;
VBOpen:=False;
Res := GetActiveObject(CLASS_ExcelApplication, nil, Unknown);
if (Res = MK_E_UNAVAILABLE) then
Excel := CoExcelApplication.Create
else begin
{ make sure no other error occurred during GetActiveObject }
OleCheck(Res);
OleCheck(Unknown.QueryInterface(_Application, Excel));
VBAppWasRunning := True;
end;
Excel.Visible[lcid] := show;
WBk := Excel.Workbooks.Open(xl_FileName, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam,
EmptyParam, LCID);
First_ws:=WBk.ActiveSheet as _Worksheet;
VBOpen:=True;
Result:=True;
Super_Text_Import:=False;
Excel_FileName:=xl_FileName;
Except
showmessage(xl_FileName #13 #10
'Unable to open MS Excel OLE object' #13 #10
'不能成功乎開啟MS Excel OLE object。');
Result:=False;
end; end; FUNCTION VBReleaseExcelObj(Save:Boolean): Boolean;
BEGIN
Result:=True;
IF VBOpen THEN
TRY
if Save and Super_Text_Import then
begin
WBk.VBProject.VBComponents.Remove(Super_Text_Import_C);
Prg_ws.Cells.Item[1,1]:='';
Prg_Ws.Delete(LCID);
end;
Excel.ActiveWindow.Close(Save,Excel_FileName,True); {Close without save} Excel.Quit;
VBOpen:=False;
Super_Text_Import:=False;
EXCEPT
showmessage('Unable to release MS Excel OLE object'
'不能成功乎釋放MS Excel OLE object,須等列印完成後方可關閉.');
Result:=False;
END;
END; procedure VBAddCodemodule;
var
LineNo: integer;
CM: CodeModule;
begin
CM := WBk.VBProject.VBComponents.Item('ThisWorkbook').Codemodule;
LineNo := CM.CreateEventProc('Open', 'Workbook');
CM.InsertLines(LineNo 1, ' Range("A1").Value = "Workbook activated!"');
//.........
end; procedure VBImport_SUPER_TEXT_String;
begin
Super_Text_Import_C:=WBk.VBProject.VBComponents.Add(vbext_ct_StdModule);
Super_Text_Import_C.CodeModule.InsertLines( 1,'Function Super_Text(The_String As String) as string');
Super_Text_Import_C.CodeModule.InsertLines( 2,'Dim i, j, k As Integer');
Super_Text_Import_C.CodeModule.InsertLines( 3,'Dim C As String');
Super_Text_Import_C.CodeModule.InsertLines( 4,'j = Len(The_String)');
Super_Text_Import_C.CodeModule.InsertLines( 5,'Super_Text = ""');
Super_Text_Import_C.CodeModule.InsertLines( 6,'For i = 1 To j');
Super_Text_Import_C.CodeModule.InsertLines( 7,' C = Mid(The_String, i, 1)');
Super_Text_Import_C.CodeModule.InsertLines( 8,' k = AscW(C)');
Super_Text_Import_C.CodeModule.InsertLines( 9,' If k < 0 or (k > 57 and k < 126 ) Or k > 255 Then');
Super_Text_Import_C.CodeModule.InsertLines(10,' Super_Text=Super_Text C');
Super_Text_Import_C.CodeModule.InsertLines(11,' Else');
Super_Text_Import_C.CodeModule.InsertLines(12,' Super_Text = Super_Text "~" Trim(Str(k))');
Super_Text_Import_C.CodeModule.InsertLines(13,' End If');
Super_Text_Import_C.CodeModule.InsertLines(14,'Next');
Super_Text_Import_C.CodeModule.InsertLines(15,'End Function'); Super_Text_Import:=True;
Prg_ws:=WBk.Worksheets.Add(EmptyParam,First_ws,1,xlWorksheet,LCID) as _worksheet;
Prg_ws.Name:='Prg_ws';
First_ws.Activate(LCID);
end; function Cell_str_por(r,c:integer):string;
var
Active_Name,Cell,super_Text:string;
begin
Result:='';
if not Super_Text_Import then
VBImport_SUPER_TEXT_String;
//VBImport_SUPER_TEXT_File; Active_Name:=First_ws.Name '!';
Cell:=Active_Name Chr(64 c) inttostr(r);
Prg_ws.Cells.Item[1,1]:='=Super_Text(' Cell ')';
super_Text:=Prg_ws.Cells.Item[1,1].Value; Result:=Convert_super_Text(super_Text);
end; function Cell_str(r,c:integer):string;
begin
Result:=First_ws.Cells.item[r,c];
end; initialization
{ReadAppIni;}
VBAppWasRunning :=False;
VBOpen :=False;
Super_Text_Import :=False;