W

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

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

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

 

우선 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건
+
제목 글쓴이 날짜 조회
08-10-30 조회 2,714
08-10-30 조회 2,814
08-10-20 조회 2,541
08-10-11 조회 2,449
08-09-20 조회 4,189
08-09-20 조회 2,858
08-09-18 조회 2,743
08-09-18 조회 3,440
08-09-17 조회 3,305
08-09-05 조회 4,641
08-09-03 조회 2,776
08-08-18 조회 2,900
08-08-17 조회 2,641
08-08-13 조회 3,422
08-07-30 조회 3,483
08-07-28 조회 4,362
08-07-22 조회 5,590
08-07-22 조회 4,077
08-07-10 조회 3,046
08-07-08 조회 3,108
08-06-30 조회 3,869
08-06-30 조회 3,351
08-06-30 조회 3,668
08-06-14 조회 2,742
08-06-11 조회 7,103
08-06-05 조회 3,317
08-05-20 조회 4,831
08-05-13 조회 4,173
08-05-08 조회 3,126
08-05-08 조회 5,281
08-04-25 조회 4,076
08-04-22 조회 4,547
08-04-21 조회 3,190
08-04-17 조회 2,570
08-04-17 조회 2,971
08-04-17 조회 2,269
08-04-17 조회 5,237
08-04-17 조회 4,556
08-04-17 조회 4,550
08-04-17 조회 3,333
08-04-17 조회 3,157
08-04-17 조회 3,642
08-04-17 조회 5,004
08-04-17 조회 5,150
08-04-17 조회 3,357
08-04-04 조회 4,620
08-04-04 조회 2,849
08-04-04 조회 2,593
08-04-04 조회 2,819
08-04-04 조회 2,553
08-04-04 조회 2,797
08-04-03 조회 2,681
08-04-03 조회 2,753
08-04-02 조회 3,065
08-04-02 조회 3,220
08-03-31 조회 3,108
08-03-26 조회 4,289
08-03-11 조회 2,974
08-03-11 조회 2,384
08-03-11 조회 2,395
08-03-07 조회 4,231
08-03-07 조회 3,323
08-03-06 조회 4,772
08-03-04 조회 3,406
08-02-19 조회 3,797
08-02-03 조회 3,421
08-01-18 조회 4,007
08-01-15 조회 3,460
08-01-12 조회 4,302
08-01-12 조회 3,870
08-01-12 조회 3,825
07-12-24 조회 3,118
07-11-30 조회 3,962
07-11-08 조회 5,021
07-11-06 조회 3,871
07-10-26 조회 5,013
07-10-24 조회 4,201
07-10-22 조회 3,586
07-10-19 조회 4,771
07-10-09 조회 4,904
07-10-09 조회 6,770
07-10-05 조회 3,106
07-10-05 조회 4,041
07-10-03 조회 7,549
07-10-03 조회 3,596
07-10-03 조회 2,948
07-10-03 조회 2,875
07-09-28 조회 4,719
07-09-27 조회 3,783
07-09-27 조회 3,231
07-09-13 조회 3,385
07-08-28 조회 3,466
07-08-04 조회 4,851
07-08-01 조회 5,546
07-08-01 조회 4,948
07-07-30 조회 5,470
07-07-29 조회 3,616
07-07-21 조회 3,438
07-07-18 조회 5,393
07-07-16 조회 3,190