dsce23640 2010-03-03 13:09
浏览 274

使用ActiveXObject(“Excel.Application”)将图像插入Excel单元格

I have a PHP Web Application, which uses the ActiveXObject to export the contents of a table into an Excel spreadsheet. I have a bit of formatting (cell alignment, currency, dates, etc,.) for some cells, but I need to merge the top 3 cells and then import an image. I've been searching, but haven't had any joy. If anyone knows if this is possible, please let me know! Cheers, Samuel

function ExportToExcel() {
    input_box=confirm("Export to Microsoft Excel?");
        if (input_box==true) {

            var xlApp = new ActiveXObject("Excel.Application");
            // Silent-mode:
            xlApp.Visible = true;
            xlApp.DisplayAlerts = false;
            var xlBook = xlApp.Workbooks.Add();
            xlBook.worksheets("Sheet1").activate;
            var XlSheet = xlBook.activeSheet;
            XlSheet.Name="Company Report";

            // Store the sheet header names in an array
            var rows = tblreport_invoice.getElementsByTagName("tr");
            var columns = tblreport_invoice.getElementsByTagName("th");
            var data = tblreport_invoice.getElementsByTagName("td");

            // Set Excel Column Headers and formatting from array
            for(i=0;i<columns.length;i++){
                XlSheet.cells(2).value= "Company Quote";
                XlSheet.cells(3,i+1).value= columns[i].innerText; //XlSheetHeader[i];
                XlSheet.cells(3,i+1).font.color="6";
                XlSheet.cells(3,i+1).font.bold="true";
                XlSheet.cells(3,i+1).interior.colorindex="37";
                XlSheet.Range("K4:K200").NumberFormat = "€ #,##0.00";
                XlSheet.Range("L4:L200").NumberFormat = "€ #,##0.00";
                XlSheet.Range("O4:O200").NumberFormat = "€ #,##0.00";
                XlSheet.Range("P4:P200").NumberFormat = "€ #,##0.00";
                XlSheet.Range("Q4:Q200").NumberFormat = "€ #,##0.00";
                XlSheet.Range("R4:R200").NumberFormat = "€ #,##0.00";
                XlSheet.Range("K4:L1000").HorizontalAlignment = -4152;
                XlSheet.Range("M4:M1000").HorizontalAlignment = -4152;
                XlSheet.Range("N4:Q1000").HorizontalAlignment = -4152;
                XlSheet.Range("R4:R1000").HorizontalAlignment = -4152;
                XlSheet.Range("F4:F1000").NumberFormat = "MM/DD/YYYY";
            }

            //run over the dynamic result table and pull out the values and insert into corresponding Excel cells
            var d = 0;
            for (r=4;r<rows.length+3;r++) { // start at row 2 as we've added in headers - so also add in another row!
                for (c=1;c<columns.length+1;c++) {
                    XlSheet.cells(r,c).value = data[d].innerText;
                    d = d + 1;
                }
            }

            //autofit the columns
            XlSheet.columns.autofit;

            // Make visible:
            xlApp.visible = true;
            xlApp.DisplayAlerts = true;
            CollectGarbage();
            //xlApp.Quit();
        }
}
  • 写回答

1条回答 默认 最新

  • doutuobao9736 2010-03-03 13:51
    关注

    // Insert company logo at top of the page

    MyPic = XlSheet.Pictures.Insert("c:\\1.jpg");
                MyPic.Top = XlSheet.Range("A1").Top;
                MyPic.Left = XlSheet.Range("A1").Left;
                MyPic.ShapeRange.Height = XlSheet.Range("A1").RowHeight * 2;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)