2012年10月25日 星期四

Delphi控制Excel(一)


delphi控制Excel(一)

內容來源:雨轩客的博客网_你的博客网

use ComObj,Excel97

首先创建 Excel 对象,使用ComObj:
var ExcelID: Variant;

ExcelID := CreateOleObject( ’Excel.Application’ );

1) 显示当前窗口:ExcelID.Visible := True;

2) 更改 Excel 标题栏: ExcelID.Caption := ’应用程序调用 Microsoft Excel’;

3) 添加新工作簿: ExcelID.WorkBooks.Add;
MsExcel.WorkBooks.Add(xlWBatWorkSheet);//增加一個WorkBook並且有一個Sheet
MSExcel.WorkBooks[1].Sheets.Add(,,17,xlWorkSheet)//在此WorkBook內在增加17個Sheet
Sheets :=XLApp.WorkBooks[1].Sheets;//指定Sheets為第一個WorkBook內的 SheetsSheets.Item[1].Name :='該Sheet的名稱';//指定此Sheets內的第一個Sheet名稱

4) 打开已存在的工作簿: ExcelID.WorkBooks.Open( ’C:\Excel\Demo.xls’ );

5) 设置第2个工作表为活动工作表: ExcelID.WorkSheets[2].Activate;
或 ExcelID.WorksSheets[ ’Sheet2’ ].Activate;

6) 给单元格赋值: ExcelID.Cells[1,4].value := ’第一行第四列’;

7) 设置指定列的宽度(单位:字符个数),以第一列为例: ExcelID.ActiveSheet.Column[1].ColumnsWidth := 5;

8) 设置指定行的高度(单位:磅)(1磅=0.035厘米),以第二行为例: ExcelID.ActiveSheet.Rows[2].RowHeight := 1/0.035; // 1厘米

9) 在第8行之前插入分页符: ExcelID.WorkSheets[1].Rows.PageBreak := 1;

10) 在第8列之前删除分页符: ExcelID.ActiveSheet.Columns[4].PageBreak := 0;

11) 指定边框线宽度: ExcelID.ActiveSheet.Range[ ’B3:D4’ ].Borders[2].Weight := 3;
1-左 2-右 3-顶 4-底 5-斜( \ ) 6-斜( / )

12) 清除第一行第四列单元格公式: ExcelID.ActiveSheet.Cells[1,4].ClearContents;

13) 设置第一行字体属性:
ExcelID.ActiveSheet.Rows[1].Font.Name := ’隶书’;
ExcelID.ActiveSheet.Rows[1].Font.Color := clBlue;
ExcelID.ActiveSheet.Rows[1].Font.Bold := True;
ExcelID.ActiveSheet.Rows[1].Font.UnderLine := True;

14) 进行页面设置:
a.页眉: ExcelID.ActiveSheet.PageSetup.CenterHeader := ’报表演示’;
b.页脚: ExcelID.ActiveSheet.PageSetup.CenterFooter := ’第&P页’;
c.页眉到顶端边距2cm: ExcelID.ActiveSheet.PageSetup.HeaderMargin := 2/0.035;
d.页脚到底端边距3cm: ExcelID.ActiveSheet.PageSetup.HeaderMargin := 3/0.035;
e.顶边距2cm: ExcelID.ActiveSheet.PageSetup.TopMargin := 2/0.035;
f.底边距2cm: ExcelID.ActiveSheet.PageSetup.BottomMargin := 2/0.035;
g.左边距2cm: ExcelID.ActiveSheet.PageSetup.LeftMargin := 2/0.035;
h.右边距2cm: ExcelID.ActiveSheet.PageSetup.RightMargin := 2/0.035;
i.页面水平居中: ExcelID.ActiveSheet.PageSetup.CenterHorizontally := 2/0.035;
j.页面垂直居中: ExcelID.ActiveSheet.PageSetup.CenterVertically := 2/0.035;
k.打印单元格网线: ExcelID.ActiveSheet.PageSetup.PrintGridLines := True;

15) 拷贝操作:
a.拷贝整个工作表: ExcelID.ActiveSheet.Used.Range.Copy;
b.拷贝指定区域: ExcelID.ActiveSheet.Range[ ’A1:E2’ ].Copy;
c.从A1位置开始粘贴: ExcelID.ActiveSheet.Range.[ ’A1’ ].PasteSpecial;
d.从文件尾部开始粘贴: ExcelID.ActiveSheet.Range.PasteSpecial;

16) 插入一行或一列:
a. ExcelID.ActiveSheet.Rows[2].Insert;
b. ExcelID.ActiveSheet.Columns[1].Insert;

17) 删除一行或一列:
a. ExcelID.ActiveSheet.Rows[2].Delete;
b. ExcelID.ActiveSheet.Columns[1].Delete;

18) 打印预览工作表: ExcelID.ActiveSheet.PrintPreview;

19) 打印输出工作表: ExcelID.ActiveSheet.PrintOut;

20) 工作表保存:
if not ExcelID.ActiveWorkBook.Saved then
ExcelID.ActiveSheet.PrintPreview;

21) 工作表另存为: ExcelID.SaveAs( ’C:\Excel\Demo1.xls’ );

22) 放弃存盘: ExcelID.ActiveWorkBook.Saved := True;

23) 关闭工作簿: ExcelID.WorkBooks.Close;

24) 退出 Excel: ExcelID.Quit;

25)释放VARIANT变量:EX:ExcelApp:=Unassigned;

知道一個excel檔內有多少個WorkSheet
XLAPP.WorkBooks[n].Sheets.Count

知道該Sheet的名稱
XLAPP.WorkBooks[n].Sheets[n].Name

打开第2个工作表
ExcelApp.Worksheets[2].activate;

打开名为第四章的工作表
ExcelApp.WorkSheets['第四章'].activate;

2010年11月11日 星期四

CCIR656與601的不同點

CCIR656與601的不同點 

用最簡單的觀念來說,CCIR656與601的不同點如下:

(1) CCIR656是標準規格,包含8-bit data與一個 CLOCK, 共9 pins, HS and VS則以特定code的形式內藏於data中。
      後端處理時,需先解出HS and VS.
   (應用時,由於是標準,不管是Front Porch, Back Porch,都是標準寬度,任何decoder解出來影像顯示在面板上的位置應該都要相同)

(2) CCIR601非標準規格,常用有8-bit與16-bit形式,另加HS, VS, CLOCK 3 pins。故8-bit mode共11 pins, 16-bit mode共19 pins.
      (應用時,由於非標準,Front Porch, Back Porch寬度可自己定義,因此大家定的有差異時,影像顯示在面板上的位置會有差異)

為減少FPC pin assignment以及免除規格不同所造成的顯示差異,故產品應用時幾乎都採用CCIR656.

另外補充CCIR656/601 (或稱YUV介面)與RGB介面的差異:

CCIR656/601傳輸影像亮度與色差訊號(Y Cb Cr),一般採用4:2:2格式(每傳四個Y,只傳兩個Cb與兩個Cr),用來降低資料傳輸量,以節省頻寬。

例如720RGBX480解析度,RGB介面傳輸資料量即為(720R+720G+720B)X480個,而CCIR656/601傳輸資料量為(720Y+480Cb+480Cr)X480,

資料量僅為RGB介面的2/3.

為何可以將Cb, Cr各丟掉一半呢?因為人眼對亮度較敏感,故Y需全傳,但人眼對顏色較不敏感,故可以丟掉部分資料不傳,

如此解出來的RGB當然會失真,但人眼不易察覺。

4:2:2格式YUV轉RGB時,輸入之YUV資料為

Cb0 Y0 Cr0 Y1 Cb2 Y2 Cr2 Y3 Cb4 Y4 Cr4 Y5 Cb6 Y6 Cr6 Y7............................

=> 輸出為

Pixel 0 (R0, G0, B0)由Cb0, Y0, Cr0轉換出來

Pixel 1 (R1, G1, B1)由Cb0, Y1, Cr0轉換出來

Pixel 2 (R2, G2, B2)由Cb2, Y2, Cr2轉換出來

Pixel 3 (R3, G3, B3)由Cb2, Y3, Cr2轉換出來

以此類推........

以上所述為基本概念,歡迎指教。

若您需要知道的更詳細,可參考附件之Video Demystified一書,謝謝。

昨天在公司看文档的时候,发现sensor部分的接口有两个标准CCIR601和CCIR656。那么CCIR601和CCIR656到底有什么区别和联系呢?
google下 看到以下叙述:
據我所知,這兩種標準都是 video transmission 的 interface,在 video frame format 的規格應該是相同的,也就是每張 frame 是 720x480, YUV 4:2:2 的格式,兩者的差別在於 interface 規格的不同,在 CCIR656 中,有 8 bit 的 data bus 和 clock 的訊號,也就是說 CCIR656 是同步傳輸的,decoder 端不用自己產生 clock。p4zu
在 CCIR601 中,訊號內包含了兩個同步訊號:Horizontal Synchronization 和 Vertical Synchronization,decoder 要自己去鎖定這個同步訊號,再自己產生 clock 來解。所以以 CCIR656 來傳遞的 video 訊號品質應該會好一些吧!gq|
1.基本上 CCIR 656 的 CLK 為 27MHz, DataBus 為 8Bits. .,?X^
CCIR 601 的 CLK 為 13.5MHz,Data為16Bits.~oq%n%
但兩者同為 YUV4:2:2,所以品質是相同的,CCIR 656 需要 9Pins、CCIR 601需要19Pins,所以CCIR 656 DATABUS較省,但CLK 較快.j`
2.CCIR 656 收到DATA後需轉換成 CCIR 601 後再轉換成 YUV4:4:4,且 CLK 需除頻(/2)為 13.5MHz;7
CCIR601 直接將 DATA 轉換成 4:4:4 即可, CLK 不變.*
3.CCIR 656 需從 DATA 中解出 VS、HS, CCIR 601 則直接使用輸入的 VS、HS 即可.W][YU
由於 CCIR 656 PIN 腳較少且 27MHz 的 CLK 對現在的 IC 根本不算快,所以使用 CCIR 656 可能會比較適合.

在《Video Demystified》第四版上,关于601和656是这样解释的。
BT.601    This ITU recommendation specifies the 720 × 480 (59.94 Hz), 960 × 480 ( 59.94 Hz), 720 × 576 (50 Hz), and 960 × 576 (50 Hz) 4:2:2 YCbCr interlaced standards.
BT.656    This ITU recommendation defines a parallel interface (8-bit or 10-bit, 27 MHz)
               and a serial interface (270 Mbps) for the transmission of 4:3 BT.601 4:2:2
               YCbCr digital video between pro-video equipment. Also see SMPTE 125M.
转自http://blog.donews.com/purecy/archive/2005/04/11/331300.aspx

What's the CCIR601
 The following contents come from http://www.wikipedia.org/wiki/CCIR_601
CCIR 601 is the old name of a standard published by the CCIR (now ITU-R) for encoding interlaced analogue video signals in digital form. It includes methods of encoding 525-line 60 Hz and 625-line 50 Hz signals, both with 720 luminance samples and 360 chrominance samples per line. The colour encoding system is known as 4:2:2, that being the ratio of Y:Cb:Cr samples (luminance data:blue chroma data:red chroma data). For a pair of pixels, the data is stored in the order Y1:Y2:Cb:Cr, with the chrominance samples co-sited with the first luminance sample.
The CCIR 601 signal can be reagarded as if it is a digitally encoded analog component video signal, and thus includes data for the horizontal and vertical sync and blanking intervals. Regardless of the frame rate, the luminance sampling frequency is 13.5 MHz. The luminance sample is at least 8 bits, and the chrominance samples are at least 4 bits each.
The first version of CCIR 601 defined only a parallel interface, but later versions introduced the bit-serial versions that are now commonly used. The 8-bit serial protocol (216 Mb/s) was once used in D1 digital tape recording. Modern standards use an encoding table to expand the data to 9 or 10 bits. The 9-bit serial version has a data rate of 243 Mb/s. The 10-bit version used in D5 digital tape recording has a data rate of 270 Mbits/s.
There is an 8-bit version in which only data from the active video periods are transmitted, with a bit rate of only 165.9 Mbit/s.
In each 8-bit luminance sample, the value 16 is used for black and 235 for white, to allow for overshoot and undershoot. The values 0 and 255 are used for sync encoding. The Cb and Cr samples use the value 128 to encode a zero value, as used when encoding a colourless area.
The CCIR 601 video raster format has been re-used in a number of later standards, including MPEG.
CCIR601 defines the sampling systems, matrix values and filter characteristics for both (Y/B-Y/R-Y) and (R/G/B) component of digital television signals.
CCIR656 is "the physical parallel and serial interconnect scheme for CCIR601". CCIR656 defines the parallel connector pinouts as well as the blanking, sync, and multiplexing schemes used in both parallel and serial interface.

收藏自: http://5geshouwang.blog.sohu.com/140738626.html