首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > VFP >

转EXCEL是对是负数标记为红色,该怎么解决

2012-08-24 
转EXCEL是对是负数标记为红色SET DATE YMDSET CENTURY ONSET SAFETY offUSE tjbbzz IN 0INDEX on 订单号+

转EXCEL是对是负数标记为红色
SET DATE YMD
SET CENTURY ON
SET SAFETY off
USE tjbbzz IN 0
INDEX on 订单号+款号 TAG sy
TOTAL ON 订单号+款号 TO temp
SELECT 20
USE temp
ALTER TABLE temp ADD 业务员 c(10)
ALTER TABLE temp ADD 交货日期 c(10)
ALTER TABLE temp ADD 计划数量 n(10)
UPDATE temp SET 业务员=tjddbzzbf.业务员,交货日期=tjddbzzbf.交货日期,计划数量=tjddbzzbf.计划数量 from tjddbzzbf WHERE ALLTRIM(temp.订单号)==ALLTRIM(tjddbzzbf.订单号)
REPLACE ALL 下差 WITH 织片-计划数量 FOR 织片<计划数量
SELECT 报表日期,业务员,交货日期,订单号,款号,计划数量,织片,下差,套口,手缝,洗水,车唛,成检 from temp INTO dbf/tmp1
USE IN temp
SELECT 1
SELECT tmp1
ncow=Reccount() &&统计记录数
SELECT * FROM tmp1 INTO CURSOR FOXTABLE
CEXCELFILE = PUTFILE("保存为(&N):","tmp1.xlsx","xlsx") &&保存为2007EXCEL版本
IF EMPTY(CEXCELFILE)
RETURN
ENDIF
SELECT FOXTABLE
OEXCELSHEET = GETOBJECT("","Excel.Sheet")
IF NOT TYPE("oExcelSheet") = "O"
= MESSAGEBOX("Excel对象创建失败,程序将中止!",16,"Error")
RETURN
ENDIF
**************************************************
OEXCEL = CREATEOBJECT("excel.application")
WITH OEXCEL
.WORKBOOKS.ADD
.SHEETS("Sheet1").SELECT
.SHEETS("Sheet1").NAME ="报表"
.VISIBLE = .F.
.DISPLAYALERTS = .F.
.ActiveWindow.DisplayZeros = .F.
.CELLS.SELECT
WITH .SELECTION.FONT
.NAME = "宋体"
.SIZE = 10
ENDWITH
ENDWITH
DLINE_S = "A1:"+CHR(ASC("A")+FCOUNT()-1)+"1"
WITH OEXCEL
.CELLS(1, 1).VALUE = "生产日报表"
.ACTIVESHEET.RANGE(DLINE_S).MERGE
.ACTIVESHEET.ROWS(1).ROWHEIGHT = 40
.RANGE(DLINE_S).SELECT
WITH .SELECTION
.FONT.NAME = "宋体"
.FONT.SIZE = 24
.FONT.BOLD = .T.
.HORIZONTALALIGNMENT = 3
.VERTICALALIGNMENT = 2
ENDWITH
ENDWITH
ROW = 2
JLS = TRANSFORM(RECCOUNT()+ROW)
RECROW = TRANSFORM(ROW+1)
ROW_BROWSE = 30
OEXCEL.ACTIVESHEET.ROWS(ROW).ROWHEIGHT = 24
OEXCEL.ACTIVESHEET.ROWS('&RECROW.:&JLS').ROWHEIGHT=20
DLINE_S = "A"+TRANSFORM(ROW)+":"+CHR(ASC("A")+FCOUNT()-1)+TRANSFORM(ROW)
OEXCEL.ACTIVESHEET.RANGE(DLINE_S).BORDERS(3).LINESTYLE = 9
FOR I = 1 TO FCOUNT()
OEXCEL.ACTIVESHEET.COLUMNS(I).COLUMNWIDTH = IIF(LEN(FIELD(I)) > FSIZE(FIELD(I)),LEN(FIELD(I)),FSIZE(FIELD(I)))
OEXCEL.CELLS(ROW, I).VALUE = FIELD(I)
OEXCEL.ACTIVEWORKBOOK.SHEETS(1).CELLS(ROW, I).HORIZONTALALIGNMENT = 3
ENDFOR
OEXCEL.RANGE(DLINE_S).SELECT
OEXCEL.SELECTION.BORDERS(-4107).LINESTYLE = 1
SCAN
IF MOD(RECNO(),ROW_BROWSE) = 1
DLINE_X = "A"+TRANSFORM(RECNO())+":"+CHR(ASC("A")+FCOUNT()-1)+TRANSFORM(RECNO())
ENDIF
FOR I = 1 TO FCOUNT("FOXTABLE")
MFIELD = FIELD(I)
WAIT WINDOW NOWAIT TRANSFORM(RECNO())+"/"+TRANSFORM(RECCOUNT())
OEXCEL.CELLS(RECNO()+ROW,I).VALUE=&MFIELD
ENDFOR
IF MOD(RECNO(),ROW_BROWSE) = 0
DLINE_X = "A"+TRANSFORM(RECNO()+ROW)+":"+CHR(ASC("A")+FCOUNT()-1)+TRANSFORM(RECNO()+ROW)
OEXCEL.ACTIVESHEET.RANGE(DLINE_X).BORDERS(4).LINESTYLE = 9
ENDIF
IF RECNO() = RECCOUNT()
DLINE_X = "A"+TRANSFORM(RECCOUNT()+ROW)+":"+CHR(ASC("A")+FCOUNT()-1)+TRANSFORM(RECCOUNT()+ROW)
OEXCEL.ACTIVESHEET.RANGE(DLINE_X).BORDERS(4).LINESTYLE = 9
ENDIF
ENDSCAN

nCols=fcount()
Selection=OEXCEL.Range(OEXCEL.Cells(2,1),OEXCEL.Cells(ncow+2,nCols)) && 设定范围为有数据的整个区域
Selection.font.size = 9 && 体字大小为 9 号
Selection.font.bold = .t. && 字体加粗
Selection.horizontalAlignment = 3 && 水平居中排列

OEXCEL.VISIBLE = .F.


OEXCEL.ACTIVEWORKBOOK.SAVEAS(CEXCELFILE)
OEXCEL.WORKBOOKS.CLOSE
OEXCEL.QUIT
RELEASE OEXCEL
WAIT CLEAR
= MESSAGEBOX("转换完毕!",64,"OK")
本论坛移过来的代码,我加了数据表,我想在转出时如果“下差”是负数的,用红色标记,如何设置,请高手帮忙,谢谢,附件已上传:统计设计

[解决办法]
*-- 如:
OEXCEL = Createobject("excel.application")
With OEXCEL
.WORKBOOKS.Add
.SHEETS("Sheet1").Select
.SHEETS("Sheet1").Name = "sample"
.Visible = .F.
.DISPLAYALERTS = .F.
.ActiveWindow.DisplayZeros = .F.
.CELLS.Select
With .Selection.Font
.Name = "宋体"
.Size = 10
Endwith
.Selection.NumberFormatLocal = "0.00_ ;[红色]-0.00"
Endwith
OEXCEL.Visible=.T.
= Messagebox("输入几个0、负数、正数,然后看一下效果!",64,"OK")
OEXCEL.WORKBOOKS.Close
OEXCEL.Quit
Release OEXCEL
[解决办法]
Selection.NumberFormatLocal = "#,##0;[红色]-#,##0"
不用判断正负

热点排行