W

로컬 텍스트 엑셀 파일 읽기/쓰기

· 2010-01-23 (토) 20:44:45 · 6870

익스플로우의 보안에 허용만 가능하면 자바스크립트 상에서도 읽기/쓰기가 가능하다.

 

우선 text파일 읽고 쓰는 예제이다.(C:\\book1.txt를 읽고 씀)

 

=====================================================================================================================

<html>
<head>
<title>file save/load</title>

 

<script type="text/javascript">

    var fso=new ActiveXObject("Scripting.FileSystemObject");
    var filename="C:\\book1.txt";
    function savefile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,2,true);
        f.Write(myarea.innerHTML);
        f.Close();
    }
   
    function loadfile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,1);
        r=f.ReadAll();
        f.Close();
        myarea.innerHTML=r;
    }
   
   
    //function window.onload() {
    //    loadfile(filename);
    //}
</script>


</head>
<body>
 <table>
  <tr>
   <td>
    <div id=myarea contenteditable=true style="width:320;height:240;border:solid 2 inset;overflow:scroll;background-color:silver;"></div>
    <br><input type=button value=load onclick=loadfile()><input type=button value=save onclick=savefile()>
   </td>
  </tr>
 </table>
</form>
</body>
</html>

 

======================================Excel 파일 열고 쓰기 =================================================

- 쓰기 -

<script type="text/javascript">

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\book1.xls");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();
</script>

 

- 열기 -

function StartExcel() {
var oExcel;

var oWBook;
oExcel = new ActiveXObject("Excel.Application");

oExcel.Visible = true;

oExcel.workbooks.open("C:/test.xls");

oExcel.Quit();

oExcel = null;
}

 

간단한 파일 읽기의 경우 상당히 유용할 수 있겠다..

 
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
11-10-25 조회 2,492
11-10-18 조회 4,017
11-10-18 조회 2,395
11-10-15 조회 3,617
11-10-10 조회 2,671
11-10-02 조회 2,589
11-09-28 조회 2,403
11-09-24 조회 2,487
11-09-22 조회 2,387
11-09-05 조회 2,875
11-08-31 조회 2,250
11-08-31 조회 2,558
11-08-31 조회 2,412
11-08-29 조회 2,962
11-08-28 조회 2,456
11-08-25 조회 2,507
11-08-17 조회 2,223
11-08-16 조회 2,460
11-08-11 조회 2,912
11-08-07 조회 2,627
11-08-03 조회 2,337
11-07-22 조회 2,080
11-07-12 조회 3,300
11-06-27 조회 2,083
11-06-01 조회 1,749
11-05-17 조회 2,536
11-05-01 조회 2,605
11-04-28 조회 2,892
11-04-28 조회 2,941
11-04-13 조회 2,600
11-03-27 조회 2,725
11-03-27 조회 2,602
11-03-14 조회 2,015
11-03-02 조회 2,339
11-03-02 조회 2,568
11-02-27 조회 2,998
11-02-23 조회 2,378
11-02-19 조회 2,519
11-02-14 조회 4,133
11-02-03 조회 2,927
11-01-24 조회 3,870
11-01-04 조회 2,400
10-12-08 조회 5,412
10-11-15 조회 2,420
10-11-14 조회 2,592
10-11-14 조회 3,611
10-10-29 조회 3,684
10-10-19 조회 2,697
10-10-07 조회 2,525
10-10-05 조회 4,443
10-09-18 조회 2,741
10-09-18 조회 2,479
10-09-17 조회 4,885
10-09-15 조회 2,823
10-09-15 조회 2,351
10-09-15 조회 2,840
10-09-15 조회 2,673
10-09-11 조회 3,998
10-09-11 조회 2,506
10-09-11 조회 2,543
10-09-07 조회 3,818
10-09-07 조회 3,354
10-08-29 조회 2,814
10-07-01 조회 3,062
10-06-30 조회 2,467
10-06-30 조회 2,649
10-06-30 조회 3,001
10-06-13 조회 2,037
10-04-15 조회 3,209
10-04-04 조회 3,438
10-02-23 조회 3,533
10-02-09 조회 3,139
10-01-25 조회 2,646
10-01-25 조회 2,744
09-12-27 조회 4,393
09-11-23 조회 3,614
09-11-20 조회 4,849
09-08-30 조회 3,048
09-08-30 조회 3,044
09-08-12 조회 3,011
09-07-22 조회 4,073
09-07-22 조회 4,719
09-07-15 조회 5,889
09-07-11 조회 2,965
09-06-17 조회 2,707
09-06-15 조회 2,993
09-05-29 조회 3,271
09-05-11 조회 5,910
09-05-08 조회 2,665
09-04-30 조회 3,781
09-04-17 조회 3,101
09-04-04 조회 3,282
09-03-05 조회 3,667
09-02-09 조회 3,636
09-02-03 조회 6,140
08-12-27 조회 3,204
08-12-20 조회 4,295
08-11-21 조회 5,255
08-11-14 조회 2,823
08-11-03 조회 3,285