W

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

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

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

 

우선 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건
+
제목 글쓴이 날짜 조회
10-10-27 조회 3,275
10-10-27 조회 2,929
10-10-27 조회 2,169
10-10-26 조회 3,279
10-10-26 조회 2,258
10-10-26 조회 2,153
10-10-26 조회 2,164
10-10-25 조회 2,097
10-10-24 조회 2,280
10-10-24 조회 2,326
10-10-24 조회 2,616
10-10-24 조회 4,783
10-10-24 조회 3,296
10-10-23 조회 2,241
10-10-23 조회 3,049
10-10-22 조회 2,086
10-10-22 조회 2,241
10-10-22 조회 3,421
10-10-22 조회 3,144
10-10-22 조회 2,171
10-10-21 조회 2,477
10-10-21 조회 2,420
10-10-21 조회 2,462
10-10-21 조회 2,604
10-10-21 조회 2,346
10-10-21 조회 2,348
10-10-21 조회 2,258
10-10-21 조회 2,432
10-10-21 조회 2,364
10-10-21 조회 2,992
10-10-21 조회 2,137
10-10-20 조회 2,105
10-10-20 조회 2,836
10-10-19 조회 2,854
10-10-19 조회 2,694
10-10-19 조회 2,243
10-10-19 조회 2,981
10-10-19 조회 2,375
10-10-19 조회 3,003
10-10-19 조회 3,422
10-10-19 조회 2,976
10-10-19 조회 9,040
10-10-19 조회 2,571
10-10-19 조회 2,722
10-10-19 조회 2,498
10-10-18 조회 2,611
10-10-18 조회 2,519
10-10-18 조회 2,593
10-10-18 조회 2,286
10-10-18 조회 3,423
10-10-17 조회 2,419
10-10-17 조회 2,291
10-10-17 조회 2,999
10-10-17 조회 2,766
10-10-16 조회 2,433
10-10-16 조회 2,337
10-10-16 조회 2,432
10-10-16 조회 2,795
10-10-16 조회 2,175
10-10-15 조회 2,281
10-10-14 조회 2,449
10-10-14 조회 3,257
10-10-13 조회 2,436
10-10-13 조회 2,574
10-10-13 조회 2,289
10-10-13 조회 2,310
10-10-12 조회 2,743
10-10-12 조회 3,040
10-10-12 조회 2,317
10-10-12 조회 2,799
10-10-11 조회 2,961
10-10-09 조회 2,390
10-10-09 조회 2,241
10-10-07 조회 2,581
10-10-07 조회 2,508
10-10-07 조회 2,224
10-10-07 조회 2,553
10-10-07 조회 2,681
10-10-07 조회 2,683
10-10-06 조회 4,637
10-10-06 조회 2,104
10-10-06 조회 2,862
10-10-06 조회 2,231
10-10-06 조회 3,057
10-10-06 조회 2,050
10-10-06 조회 2,302
10-10-05 조회 2,201
10-10-05 조회 2,251
10-10-05 조회 3,152
10-10-05 조회 4,464
10-10-05 조회 3,397
10-10-05 조회 3,366
10-10-05 조회 2,200
10-10-05 조회 2,429
10-10-05 조회 2,292
10-10-04 조회 2,087
10-10-04 조회 2,471
10-10-04 조회 2,187
10-10-04 조회 2,707
10-10-04 조회 1,965